Skip to content

Instantly share code, notes, and snippets.

@xiaodaigh
Created October 12, 2013 06:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xiaodaigh/6946423 to your computer and use it in GitHub Desktop.
Save xiaodaigh/6946423 to your computer and use it in GitHub Desktop.
Shiny R - Re-initialise reactive values
library(shiny)
shinyServer(function(input,output){
reval <- reactiveValues(a= 1,b=2,dummy= rnorm(1))
observe({
if(input$hello == 0) return()
random.number <- rnorm(1)
reval$dummy <- random.number
b <- reval$b
reval <<- reactiveValues(a = 1,b = b + 1,dummy=random.number)
})
output$a <- renderUI({
reval$dummy
HTML(reval$b)
})
})
library(shiny)
shinyUI(basicPage(
actionButton("hello","Increase Reactive Value"),
htmlOutput("a"),
HTML('<script src="https://gist.github.com/xiaodaigh/6946423.js"></script>')
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment