Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shiny how to update value that store in the reactive?

Tags:

r

shiny

Can I update/ change the value that kept in the reactive? For instance,

x <- reactive({
  isolate(input$site1)
})

# Inpsect values from ui.R.
output$test <- renderText({

    # Take a dependency on input$goButton
    input$goPlot # Re-run when button is clicked

    site1 <- isolate(input$site1)

    if(site1 == x()){
        site1
    } else {

        paste(x(), site1)
        x() <- site1 // this not working obviously.
    }

})

Any ideas?

The reason I want to do so because I want to store the previous input data input$site1 when the user click the button input$goPlot and I want to make sure the use select different option when they click the button again. If they select the same data or do not select any other option and click the button, then I don't want the app to do anything. Hope that makes sense.

like image 775
Run Avatar asked Jul 19 '15 03:07

Run


1 Answers

What you want is probably not a reactive expression but reactive values:

shinyServer(function(input, output, session) {
     values <- reactiveValues(x="someValue")

     output$test <- renderText({
         ...
         if(site1 == isolate(values$x)) {
             ...
         } else {
             ...
             values$x <- site1 
         }
     })
})
like image 76
zero323 Avatar answered Oct 06 '22 00:10

zero323