Last active
March 27, 2017 16:22
-
-
Save rpodcast/910e6f4a1a02e71f0852ebeda7c31d6c to your computer and use it in GitHub Desktop.
Using throttle/debounce with numericInputs and renderUI/uiOutput
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( | |
fluidRow( | |
numericInput( | |
"obs_low", | |
"Minimum obs", | |
value = 1000, | |
min = 500, | |
max = 5000, | |
step = 100 | |
), | |
numericInput( | |
"obs_max", | |
"Maximum obs", | |
value = 4000, | |
min = 500, | |
max = 10000, | |
step = 100 | |
), | |
uiOutput("likely_ui") | |
) | |
) | |
server <- function(input, output, session) { | |
output$likely_ui <- renderUI({ | |
# obtain the min and max obs | |
min_obs <- input$obs_low | |
max_obs <- input$obs_max | |
median_obs <- reactive({ | |
median(c(input$obs_low, input$obs_max)) | |
}) | |
min_obs_d <- reactive({ input$obs_low }) %>% debounce(1000) | |
max_obs_d <- reactive({ input$obs_max }) %>% debounce(1000) | |
median_obs_d <- debounce(median_obs, 1000) | |
validate( | |
need(min_obs < max_obs, "Minimum obs must be less than maximum obs!") | |
) | |
tagList( | |
sliderInput( | |
"prev_likely", | |
"Most Likely obs", | |
min = min_obs_d(), | |
max = max_obs_d(), | |
value = median_obs_d(), | |
sep = "," | |
) | |
) | |
}) | |
} | |
shinyApp(ui = ui, server = server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment