-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
152 lines (129 loc) · 5.73 KB
/
app.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# load packages
library(shiny)
library(shinydashboard)
# load module scripts
source('module.R')
ui <- dashboardPage(
skin = 'purple',
dashboardHeader(title = 'Modular app demo'
,tags$li(class = "dropdown"
,tags$a(icon("github")
,href = "https://github.com/M3IT/shiny_modular_code_demo"
,title = "See the code on github"
)
))
,dashboardSidebar(sidebarMenuOutput('menu') #), #sidebarMenu(id = 'sbmnu') #,
,hr()
,tags$style("#si_sidebar {background-color:#fa984d;}") # selectize = F for colour to work
,selectInput('si_sidebar', 'Selector Sidebar', c('sb_abc', 'sb_def', 'sb_ghi'), selectize = F)
,hr()
,textOutput('sidebar_text_1'), br()
,textOutput('sidebar_text_2'), br()
,textOutput('sidebar_text_3'), br()
,textOutput('sidebar_text_4'), br()
)
,dashboardBody(
tags$head(tags$style(HTML('
/* body */
.content-wrapper, .right-side {
/* background-color: #7da2d1; */
padding-top: 0px;
padding-left: 10px;
padding-right: 10px;
padding-bottom: 0px;
}
#wp_1 {background-color: #969cf2}
#wp_2 {background-color: #fa984d}
#wp_3 {background-color: #69dbb3}
#wp_4 {background-color: #dce058}
#sidebar_text_1 {color: #000000; background-color: #969cf2}
#sidebar_text_2 {color: #000001; background-color: #fa984d}
#sidebar_text_3 {color: #000000; background-color: #69dbb3}
#sidebar_text_4 {color: #000000; background-color: #dce058}
')))
,h3('Main body content')
,tags$style("#si_main_body {background-color:#969cf2;}")
,selectInput('si_main_body', 'Selector Main Body', c('main_ui_ABC', 'main_ui_DEF', 'main_ui_GHI'), selectize = F)
,fluidRow(
column(width = 3, 'Main selector', br(), wellPanel(id = 'wp_1', textOutput('main_ui_text_1')))
,column(width = 3, 'Side panel selector', br(), wellPanel(id = 'wp_2', textOutput('main_ui_text_2')))
,column(width = 3, 'Tab 1 selector', br(), wellPanel(id = 'wp_3', textOutput('main_ui_text_3')))
,column(width = 3, 'Tab 2a selector', br(), wellPanel(id = 'wp_4', textOutput('main_ui_text_4')))
)
,tags$hr(style = "border-color: purple;")
,fluidRow(
tabItems(
tabItem(tabName = 'dashboard1'
,h4('Dashboard tab 1 content')
,fluidRow(
column(width = 12, wellPanel(varselect_mod_ui('vars_tab_1')))
)
)
,tabItem(tabName = 'dashboard2', h4('Dashboard tab 2 content'))
,tabItem(tabName = 'dashboard2A'
,h4('Dashboard tab 2a content')
,column(width = 8, wellPanel(varselect_mod_ui('vars_tab_2a')))
)
)
)
)
)
# server logic
server <- function(input, output, session) {
session$onSessionEnded(stopApp) # End session if browser tab closed
output$menu <- renderMenu({
sidebarMenu(
id = 'sbmnu'
,menuItem(text = 'Tab 1', tabName = 'dashboard1')
,menuItem(text = 'Tab 2', tabName = 'dashboard2'
,menuSubItem(text = 'Sub Tab 2A', tabName = 'dashboard2A')
)
)
})
# execute variable selection modules
varsTab1 <- callModule(varselect_mod_server, 'vars_tab_1', other_vals = other_mod_vals)
varsTab2a <- callModule(varselect_mod_server, 'vars_tab_2a', other_vals = other_mod_vals)
other_mod_vals <- reactive({
list(omv_main, omv_sidebar, omv_tab_1, omv_tab_2b)
})
# Other_mod_vals
omv_main <- reactive({
return(input$si_main_body)
})
omv_sidebar <- reactive({
return(input$si_sidebar)
})
omv_tab_1 <- reactive({
return(varsTab1$mvar())
})
omv_tab_2b <- reactive({
return(varsTab2a$mvar())
})
# Outputs
output$main_ui_text_1 <- renderText({
omv_main()
})
output$main_ui_text_2 <- renderText({
omv_sidebar()
})
output$main_ui_text_3 <- renderText({
omv_tab_1()
})
output$main_ui_text_4 <- renderText({
omv_tab_2b()
})
output$sidebar_text_1 <- renderText({
omv_main()
})
output$sidebar_text_2 <- renderText({
omv_sidebar()
})
output$sidebar_text_3 <- renderText({
omv_tab_1()
})
output$sidebar_text_4 <- renderText({
omv_tab_2b()
})
}
# Run the application
shinyApp(ui = ui, server = server)