I am building a simple survey-like shiny app. I record user responses to several questions using sliders. In the case the participant response is equal to the initial value of the slider, I would like to know whether the participant intentionally left it in that position or not.
I'm consider either of the following options, but I don't know how to do neither of both: a- enforce participants to move the slider before submitting the response. b- set starting slider value at 'NULL' or something similar (meaning the slider cursor is hidden until first click on the slider).
I would go for option 3, make a flag which is set whenever the slider is changed and depending on that you do something different. For instance:
library(shiny)
ui <- fluidPage(sliderInput("sld", "Value", 1, 10, 1),
actionButton("go", "Validate"),
verbatimTextOutput("out"))
server <- function(input, output, session) {
has_changed <- reactiveVal(FALSE)
observeEvent(input$sld, {
## whenever the slider changes flag it
has_changed(TRUE)
},
## use ignoreInit to avoid firing on startup
ignoreInit = TRUE)
output$out <- renderPrint({
input$go
if (isolate(has_changed())) {
"Changed!"
} else {
"Never Changed"
}})
}
shinyApp(ui, server)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With