-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtemplate_2.R
62 lines (52 loc) · 1.03 KB
/
template_2.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
library(shiny)
library(ggplot2)
graph_UI <- function(id) {
ns <- NS(id)
tagList(
selectInput(
inputId = ns("plottype"),
label = "plot type",
choices = c("boxplot", "histogram")
),
plotOutput(
outputId = ns("plot_1")
)
)
}
graph_server <- function(id) {
moduleServer(
id,
function(input, output, session) {
output$plot_1 <- renderPlot({
p <- ggplot(mtcars, aes(x = mpg))
if (input$plottype == "boxplot") {
p <- p + geom_boxplot()
} else {
p <- p + geom_histogram()
}
p
})
}
)
}
ui <- fluidPage(
actionButton(
inputId = "add_module",
label = "Add a module"
),
div(
id = "add_here"
)
)
server <- function(input, output, session) {
observeEvent(input$add_module, {
graph_server(
id = paste0("id_", input$add_module)
)
insertUI(
selector = "#add_here",
ui = graph_UI(id = paste0("id_", input$add_module))
)
})
}
shinyApp(ui, server)