-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
118 lines (100 loc) · 3 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
library(shiny)
library(bslib)
library(plotly)
source('read_data.R')
source('make_plot.R')
source('make_table.R')
source('write_inputs.R')
ui <- tagList(
bslib::page_navbar(
title = tags$div(
shiny::img(
src = "logo-shiny.png",
height = 50,
width = 45,
style = "margin:10px 10px"
),
"bdasap"
),
theme = bslib::bs_theme(
"navbar-bg" = "white",
"bs-navbar-active-color" = "#044ed7",
base_font = font_google("Red Hat Display"),
heading_font = font_google("Red Hat Display")
),
sidebar = NULL,
nav_panel("Plot",
tags$div(class="left-margin",
tags$div(
class="custom-flexbox",
selectInput("trta", "Treatments", NULL, multiple = TRUE),
selectInput("param", "Parameters", NULL, multiple = TRUE, width = '900px'),
actionButton("print", "Print Plot")
),
h1("Plot of Labs"),
uiOutput('subtitle')
),
plotlyOutput("plot")
),
nav_panel("Table", NULL)
),
shiny::includeCSS("www/styles.css")
)
server <- function(input, output, session) {
# a reactive value monitors input dependencies
data <- reactive(read_data())
# reactiveValues
all_inputs <- reactiveValues(trta = NULL, param = NULL)
################### PLOT #####################
# observeEvent can be refactored using bindEvent
# to an observe + bindEvent()
observe({
# this is a little contrived but pretend we need this value
# and all inputs have a listener attached
input$print
updateSelectInput(
session,
"trta",
choices = unique(data()$adlb$TRTA),
selected = unique(data()$adlb$TRTA)
)
updateSelectInput(
session,
"param",
choices = unique(data()$adlb$PARAM),
selected = unique(data()$adlb$PARAM)
)
}) %>%
bindEvent(data())
output$subtitle <- renderUI({
tags$div(
class="subtitle",
paste0(
"Averaged measurements of selected parameters by treatments: ",
paste(input$trta, collapse = ", "),
" over the course of the study."
)
)
})
output$plot <- renderPlotly({
make_plot(data()$adlb, input$trta, input$param)
})
############### TABLE ##########################
# this can be refactored using bindEvent
manipulated_data <- reactive(make_table(data()$adlb)) %>%
bindEvent(data())
# we'll use this table
# in our table tab next session!
################ Exercise ##################
# set up a listener to update all_values
# from NULL to the currently selected inputs
# for param and trta
#
#
# we'll eventually use this object
# to store selections in a database!
onStop(function(){
write_inputs(all_inputs)
})
}
shinyApp(ui, server)