Last active
January 24, 2018 09:27
-
-
Save tmasjc/4f32da5a5a935c9175df87d70bbe5ed8 to your computer and use it in GitHub Desktop.
Reactive value in Shiny #shiny
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
ui <- fluidPage( | |
column(12, | |
# toggle between normal or uniform distribution | |
actionButton("rnorm", "Normal"), | |
actionButton("runif", "Uniform") | |
), | |
column(12, | |
plotOutput("plot") | |
) | |
) | |
server <- function(input, output, session) { | |
# initiate a 'reactive variable' | |
df <- reactiveVal(rnorm(100)) | |
output$plot <- renderPlot({ | |
hist(df()) | |
}) | |
observeEvent(input$rnorm, { | |
# update value | |
df(rnorm(100)) | |
## OR | |
# new <- rnorm(100) | |
# df(new) | |
}) | |
observeEvent(input$runif, { | |
df(runif(100)) | |
}) | |
} | |
shinyApp(ui, server, options = list(height = 500)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment