Created
October 5, 2018 20:43
-
-
Save skohari/7a432edce6bf45ee4553d279d7605b1d to your computer and use it in GitHub Desktop.
reactiveValues; for values to be 'floating', and not `fixed`.
This file contains hidden or 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
ui <- fluidPage( | |
actionButton("minus", "-1"), | |
actionButton("plus", "+1"), | |
br(), | |
textOutput("value") | |
) | |
# The comments below show the equivalent logic using reactiveValues() | |
server <- function(input, output, session) { | |
value <- reactiveVal(0) # rv <- reactiveValues(value = 0) | |
observeEvent(input$minus, { | |
newValue <- value() - 1 # newValue <- rv$value - 1 | |
value(newValue) # rv$value <- newValue | |
}) | |
observeEvent(input$plus, { | |
newValue <- value() + 1 # newValue <- rv$value + 1 | |
value(newValue) # rv$value <- newValue | |
}) | |
output$value <- renderText({ | |
value() # rv$value | |
}) | |
} | |
shinyApp(ui, server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment