forked from aimeegott/RStudio-Conf-Intermediate-Shiny
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleft_right_01.R
87 lines (67 loc) · 2.02 KB
/
left_right_01.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
library(shiny)
# Module 1: Dataset chooser ---------------------------------------------------
# Module 1 UI
dataset_chooser_UI <- function(id) {
ns <- NS(id)
tagList(
selectInput(ns("dataset"), "Choose a dataset", c("pressure", "cars")),
numericInput(ns("count"), "Number of records to return", 10)
)
}
# Module 1 Server
dataset_chooser <- function(input, output, session) {
dataset <- reactive({
req(input$dataset)
get(input$dataset, pos = "package:datasets")
})
return(list(
dataset = dataset,
count = reactive(input$count)
))
}
# Module 2: Dataset summarizer ------------------------------------------------
# Module 2 UI
dataset_summarizer_UI <- function(id) {
ns <- NS(id)
verbatimTextOutput(ns("summary"))
}
# Module 2 Server
dataset_summarizer <- function(input, output, session, dataset, count) {
output$summary <- renderPrint({
summary(head(dataset(), count()))
# paste("The mean of", colnames(dataset())[1], "is", mean(dataset()[,1]))
# paste("The mean of", colnames(dataset())[2], "is", mean(dataset()[,2]))
})
# Make a list output for the means
}
# Module 3 UI
dataset_plotter_UI <- function(id) {
ns <- NS(id)
tagList(
)
}
dataset_plotter <- function(input, output, session) {
}
# Module 3 Server
# App combining Module 1 and Module 2 -----------------------------------------
# App UI
ui <- fluidPage(
fluidRow(
column(6,
dataset_chooser_UI("left_input"),
dataset_summarizer_UI("left_output")
),
column(6,
dataset_chooser_UI("right_input"),
dataset_summarizer_UI("right_output")
)
)
)
# App server
server <- function(input, output, session) {
left_result <- callModule(dataset_chooser, "left_input")
right_result <- callModule(dataset_chooser, "right_input")
callModule(dataset_summarizer, "left_output", dataset = left_result$dataset, count = left_result$count)
callModule(dataset_summarizer, "right_output", dataset = right_result$dataset, count = right_result$count)
}
shinyApp(ui, server)