-
Notifications
You must be signed in to change notification settings - Fork 8
/
module_observeEvent.R
40 lines (35 loc) · 944 Bytes
/
module_observeEvent.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
library(shiny)
## Module with observeEvent().
## Module uses observeEvent() to reset slider value after actionButton().
sliderTextUI <- function(id) {
ns <- NS(id)
tagList(
sliderInput(ns("slider"), "Slide me", 0, 100, 5),
textOutput(ns("number"))
)
}
sliderText <- function(input, output, session, show, reset) {
output$number <- renderText({
if(show())
input$slider
else
NULL
})
observeEvent(reset(), {
updateSliderInput(session, "slider", value=0)
})
reactive({input$slider + 5})
}
ui <- fluidPage(
actionButton("reset", "Reset Value"),
checkboxInput("display", "Show Value"),
sliderTextUI("module"),
h2(textOutput("value"))
)
server <- function(input, output) {
reset <- reactive({input$reset})
display <- reactive({input$display})
num <- callModule(sliderText, "module", display, reset)
output$value <- renderText({paste0("slider1+5: ", num())})
}
shinyApp(ui, server)