updateOrderInput does not work with named vector or named list
ltuijnder opened this issue · comments
Lennart Tuijnder commented
Bug description
When updating the items
argument of a shinyjqui::orderInput
widget via updateOrderInput
, unexpected results occur when the updated items is a named vector or named list.
- The following message is printed in console:
Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.
- Only the first vector/list item is shown in the widget on the browser.
- The value returned by
input$inputID
="[object Object]"
(screenshot taken from app example below)
Minimal example:
library(shiny)
library(shinyjqui)
## Uncomment the one you want to use
#toUpdate <- month.abb[1:6] # Normal vector works fine
#toUpdate <- stats::setNames(1:6, nm = month.abb[1:6]) # Named vector does not work
#toUpdate <- as.list(stats::setNames(1:6, nm = month.abb[1:6])) # Named list does not work
#toUpdate <- factor(month.abb[1:6]) # Factor works.
ui <- fluidPage(
orderInput("foo", "label",
items = NULL,
item_class = 'default'),
verbatimTextOutput("order"),
actionButton("update", "update")
)
server <- function(input, output, session) {
output$order <- renderPrint({input$foo})
observeEvent(input$update, {
updateOrderInput(
session, "foo",
items = toUpdate
)
})
}
shinyApp(ui, server)
The specifying a named vector or list in orderInput
seems to be no problem.
Extra sessionInfo:
> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.3 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=de_BE.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=de_BE.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=de_BE.UTF-8 LC_NAME=de_BE.UTF-8
[9] LC_ADDRESS=de_BE.UTF-8 LC_TELEPHONE=de_BE.UTF-8
[11] LC_MEASUREMENT=de_BE.UTF-8 LC_IDENTIFICATION=de_BE.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] shinyjqui_0.4.0 shiny_1.7.1 rj_4.0.5-4
loaded via a namespace (and not attached):
[1] Rcpp_1.0.7 xml2_1.3.2 magrittr_2.0.1 rj.gd_4.0.5-1
[5] xtable_1.8-4 R6_2.5.1 rlang_0.4.12 fastmap_1.1.0
[9] tools_3.6.3 jquerylib_0.1.4 htmltools_0.5.2 ellipsis_0.3.2
[13] digest_0.6.28 lifecycle_1.0.1 crane_0.0.3 later_1.3.0
[17] sass_0.4.0 htmlwidgets_1.5.4 promises_1.2.0.1 curl_4.3.2
[21] cachem_1.0.6 mime_0.12 compiler_3.6.3 bslib_0.3.1
[25] jsonlite_1.7.2 httpuv_1.6.3
Yang Tang commented
Hi @ltuijnder Thanks for identifying the issue. The named vector should now work in orderInput()
Lennart Tuijnder commented
Hi @Yang-Tang, I can confirm that the bug has been fixed in the latest release 0.4.1.
.
Thank you for your work!