Skip to content

Instantly share code, notes, and snippets.

@tmasjc
Last active January 24, 2018 09:27
Show Gist options
  • Save tmasjc/4f32da5a5a935c9175df87d70bbe5ed8 to your computer and use it in GitHub Desktop.
Save tmasjc/4f32da5a5a935c9175df87d70bbe5ed8 to your computer and use it in GitHub Desktop.
Reactive value in Shiny #shiny
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