Skip to content
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

updateOrderInput does not work with named vector or named list #81

Closed
ltuijnder opened this issue Nov 26, 2021 · 2 comments
Closed

updateOrderInput does not work with named vector or named list #81

ltuijnder opened this issue Nov 26, 2021 · 2 comments
Labels

Comments

@ltuijnder
Copy link

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.

  1. 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.
  2. Only the first vector/list item is shown in the widget on the browser.
  3. The value returned by input$inputID = "[object Object]" (screenshot taken from app example below)
    screenshot taken from the 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
Copy link
Owner

Hi @ltuijnder Thanks for identifying the issue. The named vector should now work in orderInput()

@Yang-Tang Yang-Tang added the bug label Dec 29, 2021
@ltuijnder
Copy link
Author

Hi @Yang-Tang, I can confirm that the bug has been fixed in the latest release 0.4.1..

Thank you for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants