following the MWE on the ReadMe page on github, I created a minimal shiny app with one slider and one checkbox, whereby in both
cases cookies are set and retrieved via observeEvent, the problem is that after I reload the app everything works fine for the sliderInput but for the checkbox the value is constantly set to TRUE after reload, even though I do not click it.
library(cookies)
library(shiny)
ui <- add_cookie_handlers(
fluidPage(
titlePanel("A Simple App"),
fluidRow(
sliderInput(
"number_selector",
label = paste(
"Select a number.",
"This selector sets the cookie value.",
"It also initializes with the cookie value.",
"Refresh to see it remembered.",
sep = "\n"
),
min = 1,
max = 10,
value = 1
), checkboxInput("check", "Checkbox", value = FALSE))))
Hello,
following the MWE on the ReadMe page on github, I created a minimal shiny app with one slider and one checkbox, whereby in both cases cookies are set and retrieved via observeEvent, the problem is that after I reload the app everything works fine for the sliderInput but for the checkbox the value is constantly set to TRUE after reload, even though I do not click it.
library(cookies) library(shiny)
ui <- add_cookie_handlers( fluidPage( titlePanel("A Simple App"), fluidRow( sliderInput( "number_selector", label = paste( "Select a number.", "This selector sets the cookie value.", "It also initializes with the cookie value.", "Refresh to see it remembered.", sep = "\n" ), min = 1, max = 10, value = 1 ), checkboxInput("check", "Checkbox", value = FALSE))))
server <- function(input, output, session) { observeEvent( input$number_selector, { set_cookie( cookie_name = "selected_number", cookie_value = input$number_selector ) } )
observeEvent( get_cookie("selected_number"), updateSliderInput( inputId = "number_selector", value = get_cookie("selected_number") ), once = TRUE )
observeEvent( input$check, { set_cookie( cookie_name = "check_cookie", cookie_value = input$check ) })
observeEvent( get_cookie("check_cookie"), updateSliderInput( inputId = "check", value = get_cookie("check_cookie") ), once = TRUE)}
shinyApp(ui, server, options = list( launch.browser = TRUE ))