-
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cookie with checkboxes #81
Comments
@Estateira Thank you for this report! I'm sorry it took me so long to get back to you; I managed to lose this report in my inbox, and finally got to it today! There are two issues here:
In any case, thank you for bringing this to my attention! This is a working version of your app: 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"),
updateCheckboxInput(
inputId = "check",
value = as.logical(get_cookie("check_cookie"))
),
once = TRUE
)
}
shinyApp(ui, server, options = list( launch.browser = TRUE )) BTW, if you don't already have something similar, I find the Cookie-Editor Chrome extension extremely helpful when working on things that involve cookies! It took me a while to sort out what was happening in this case, but seeing "true" and "false" instead of |
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 ))
The text was updated successfully, but these errors were encountered: