From ac5b6834e8d28b560b3523829aba190203d44321 Mon Sep 17 00:00:00 2001 From: aoles Date: Mon, 8 Aug 2016 15:25:39 +0200 Subject: [PATCH] Properly restore multi-select inputs and checkbox groups with no default value when only one item is selected (fixes https://github.com/aoles/shinyURL/issues/5 and https://github.com/aoles/shinyURL/issues/8 --- DESCRIPTION | 2 +- R/server.R | 6 ++++-- inst/examples/widgets/ui.R | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 29a9338..6ae64b6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: shinyURL Type: Package Title: Save and restore the state of Shiny apps -Version: 0.0.34 +Version: 0.0.35 Encoding: UTF-8 Author: Andrzej Oleś Maintainer: Andrzej Oleś diff --git a/R/server.R b/R/server.R index 55d69ea..4b08734 100644 --- a/R/server.R +++ b/R/server.R @@ -80,7 +80,7 @@ shinyURL.server = function(session, options) { q = if (is.list(q)) { ## checkbox group or multiple select - unname(q) + unlist(q, use.names=FALSE) } else { ## decode range vectors (sliders and dates) @@ -92,6 +92,8 @@ shinyURL.server = function(session, options) { if (cl=="integer") cl = "numeric" switch(cl, + ## selectInput without default value is initially set to NULL + NULL = q, ## Dates need to be handled separately Date = format(as.Date(as.numeric(q), "1970-01-01"), "%Y-%m-%d"), ## default case; should allow to correctly decode TRUE/FALSE @@ -123,7 +125,7 @@ shinyURL.server = function(session, options) { if (length(inputValues)==0) return() ## remove actionButtons - isActionButton = unlist(lapply(inputValues, function(x) inherits(x, "shinyActionButtonValue")), use.names=FALSE) + isActionButton = unlist(lapply(inputValues, inherits, "shinyActionButtonValue"), use.names=FALSE) inputValues = inputValues[!isActionButton] ## remove ggvis specific inputs diff --git a/inst/examples/widgets/ui.R b/inst/examples/widgets/ui.R index 0f5b47e..e39bd42 100644 --- a/inst/examples/widgets/ui.R +++ b/inst/examples/widgets/ui.R @@ -77,7 +77,7 @@ shinyUI(fluidPage( )), column(4, wellPanel( - selectInput("multiselect", label = h3("Multiple select"), choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3), selected = 1, multiple = TRUE) + selectInput("multiselect", label = h3("Multiple select"), choices = list("Choice A" = "a", "Choice B" = "b", "Choice C" = "c"), multiple = TRUE) )), column(4, wellPanel(