Skip to content

Commit b34bca0

Browse files
authored
Merge pull request #703 from SafetyGraphics/fix-701
basic profile integration
2 parents c95f77d + 23c25ab commit b34bca0

8 files changed

Lines changed: 173 additions & 15 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Suggests:
2121
ggplot2 (>= 3.3.0),
2222
knitr (>= 1.34),
2323
rmarkdown (>= 2.10),
24+
safetyProfile,
2425
shinydashboard (>= 0.7.1),
2526
shinytest (>= 1.5.0),
2627
testthat (>= 3.0.4),

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export(mappingSelectUI)
3333
export(mappingTab)
3434
export(mappingTabUI)
3535
export(prepareChart)
36+
export(profileTab)
37+
export(profileTabUI)
3638
export(safetyGraphicsApp)
3739
export(safetyGraphicsInit)
3840
export(safetyGraphicsServer)

R/mod_profileTab.R

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#' @title UI for the profile module in safetyProfile::profile_ui
2+
#'
3+
#' @param id module id
4+
#'
5+
#' @export
6+
7+
profileTabUI <- function(id){
8+
ns <- NS(id)
9+
10+
if(isNamespaceLoaded("safetyProfile")){
11+
profile_ui<-list(
12+
h1(paste("Participant Profile")),
13+
span("This page shows details for a selected participant."),
14+
profile_ui(ns("profile"))
15+
)
16+
}else{
17+
profile_ui<-NULL
18+
}
19+
return(profile_ui)
20+
}
21+
22+
23+
#' @title Server for the patient profile in safetyProfile::profile_server
24+
#'
25+
#' @param input Shiny input object
26+
#' @param output Shiny output object
27+
#' @param session Shiny session object
28+
#' @param params reactive containing mapping and data
29+
#' @param current_id reactive containing currently selected participant
30+
#'
31+
#' @return current_id
32+
#'
33+
#' @import datamods
34+
#' @importFrom shinyjs show hide
35+
#' @importFrom shiny renderDataTable
36+
#'
37+
#' @export
38+
39+
profileTab <- function(input, output, session, params) {
40+
id <- safetyProfile::profile_server(
41+
"profile",
42+
params
43+
)
44+
45+
observe({
46+
shinyjs::html(
47+
"pt-header",
48+
id(),
49+
asis=TRUE
50+
)
51+
52+
shinyjs::toggleClass(
53+
selector = "#pt-header",
54+
class = "active",
55+
condition = !is.null(id())
56+
)
57+
})
58+
59+
return(id)
60+
}

R/mod_safetyGraphicsServer.R

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@ safetyGraphicsServer <- function(input, output, session,
2626
filterDomain,
2727
config
2828
) {
29-
# Initialize the Home tab
29+
#--- Home tab ---#
3030
callModule(
3131
homeTab,
3232
"home",
3333
config
3434
)
3535

36-
# Initialize the Mapping tab - returns the current mapping as a reactive
36+
#--- Mapping tab ---#
3737
current_mapping<-callModule(
3838
mappingTab,
3939
"mapping",
4040
meta,
4141
domainData
4242
)
4343

44-
# Initialize the Filter tab - returns list of filtered data as a reactive
44+
#--- Filter tab ---#
4545
filtered_data<-callModule(
4646
filterTab,
4747
"filter",
@@ -50,16 +50,35 @@ safetyGraphicsServer <- function(input, output, session,
5050
current_mapping=current_mapping
5151
)
5252

53-
# Initialize Charts tab
54-
# Initialize Chart UI - adds subtabs to chart menu and initializes the chart UIs
55-
#charts %>% purrr::map(
56-
# ~chartsNav(
57-
# .x,
58-
# session$ns
59-
# )
60-
#)
53+
#--- Profile tab ---#
54+
if(isNamespaceLoaded("safetyProfile")){
55+
callModule(
56+
profileTab,
57+
"profile",
58+
params = reactive({
59+
list(
60+
data=filtered_data(),
61+
settings=safetyGraphics::generateMappingList(current_mapping())
62+
)
63+
})
64+
)
65+
66+
observeEvent(input$participants_selected, {
67+
cli::cli_alert_info('Selected participant ID: {input$participants_selected}')
6168

62-
# Initialize Chart Servers
69+
# Update selected participant.
70+
updateSelectizeInput(
71+
session,
72+
inputId = 'profile-profile-idSelect',
73+
selected = input$participants_selected
74+
)
75+
})
76+
} else {
77+
shinyjs::hide(selector = paste0(".navbar li a[data-value='profile']"))
78+
shinyjs::hide(selector = paste0(".navbar #pt-header"))
79+
}
80+
81+
#--- Charts tab ---#
6382
charts %>% purrr::walk(
6483
~callModule(
6584
module=chartsNav,
@@ -70,7 +89,7 @@ safetyGraphicsServer <- function(input, output, session,
7089
)
7190
)
7291

73-
# Initialize the Setting tab
92+
#--- Settings tab ---#
7493
callModule(
7594
settingsTab,
7695
"settings",

R/mod_safetyGraphicsUI.R

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@ safetyGraphicsUI <- function(id,
3838
"\");"
3939
))
4040
)
41+
42+
pt_selected<-tags$script(
43+
HTML(paste0(
44+
"var header = $('.navbar > .container-fluid');",
45+
"header.append(\"",
46+
"<div id='pt-header' class='badge' title='Selected Participant'>",
47+
"None",
48+
"</div>",
49+
"\");",
50+
"var ptheader = $('.navbar > .container-fluid > #pt-header');",
51+
"ptheader.on('click',function(){",
52+
"$('",
53+
'[data-value="profile"]',
54+
"').tab('show');",
55+
"})"
56+
))
57+
)
58+
4159
if(isNamespaceLoaded("shinybusy")){
4260
spinner<-shinybusy::add_busy_spinner(spin = "atom", position="bottom-right")
4361
}else{
@@ -80,10 +98,17 @@ safetyGraphicsUI <- function(id,
8098
tabPanel("Home", icon=icon("home"), homeTabUI(ns("home"))),
8199
tabPanel("Mapping", icon=icon("map"), mappingTabUI(ns("mapping"), meta, domainData, mapping, standards)),
82100
tabPanel("Filtering", icon=icon("filter"), filterTabUI(ns("filter"))),
101+
tabPanel(
102+
"Profile",
103+
icon=icon("person"),
104+
value='profile',
105+
profileTabUI(ns("profile"))
106+
),
83107
chartNav,
84108
tabPanel('',icon=icon("cog"), settingsTabUI(ns("settings")))
85109
),
86-
participant_badge
110+
participant_badge,
111+
pt_selected
87112
)
88113
return(ui)
89114
}

inst/www/index.css

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,20 @@ table.metatable.dataTable tr > td:last-of-type, table.metatable.trdataTable tr >
6464
margin-top:1em;
6565
}
6666

67+
#pt-header.active {
68+
background:#4B9CD3;
69+
text-decoration:underline;
70+
cursor:pointer;
71+
}
72+
73+
#pt-header {
74+
float: right;
75+
margin-top: 1em;
76+
margin-right:1em;
77+
}
78+
6779
#population-header.subset {
68-
background: blue;
80+
background: green;
6981
}
7082

7183
#dataSettings-previews .nav-tabs{

man/profileTab.Rd

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/profileTabUI.Rd

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)