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

shiny example error #39

Open
kateodziomek opened this issue Feb 17, 2021 · 3 comments
Open

shiny example error #39

kateodziomek opened this issue Feb 17, 2021 · 3 comments

Comments

@kateodziomek
Copy link

I get a following error when I try to run your shiny examples (both the jsonedit and reactjson one produce the same error):

ERROR: 'options' must be a fully named list, or have no names (NULL)

Any ideas as to why this might be happening?

Apologies for brevity but I haven't really been able to do much here.

> sessioninfo::session_info()
- Session info ----------------------------------------------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.6.1 (2019-07-05)
 os       Windows 10 x64              
 system   x86_64, mingw32             
 ui       RStudio                     
 language (EN)                        
 collate  English_United Kingdom.1252 
 ctype    English_United Kingdom.1252 
 tz       Europe/London               
 date     2021-02-17                  

- Packages --------------------------------------------------------------------------------------------------------------------------------------------------------
 package     * version date       lib source        
 assertthat    0.2.1   2019-03-21 [1] CRAN (R 3.6.3)
 bslib         0.2.4   2021-01-25 [1] CRAN (R 3.6.3)
 cachem        1.0.1   2021-01-21 [1] CRAN (R 3.6.3)
 cli           2.3.0   2021-01-31 [1] CRAN (R 3.6.3)
 crayon        1.4.0   2021-01-30 [1] CRAN (R 3.6.3)
 digest        0.6.27  2020-10-24 [1] CRAN (R 3.6.3)
 ellipsis      0.3.1   2020-05-15 [1] CRAN (R 3.6.3)
 fastmap       1.1.0   2021-01-25 [1] CRAN (R 3.6.3)
 glue          1.4.2   2020-08-27 [1] CRAN (R 3.6.3)
 htmltools     0.5.1.1 2021-01-22 [1] CRAN (R 3.6.3)
 htmlwidgets   1.5.3   2020-12-10 [1] CRAN (R 3.6.3)
 httpuv        1.5.5   2021-01-13 [1] CRAN (R 3.6.3)
 jquerylib     0.1.3   2020-12-17 [1] CRAN (R 3.6.3)
 jsonlite      1.7.2   2020-12-09 [1] CRAN (R 3.6.3)
 later         1.1.0.1 2020-06-05 [1] CRAN (R 3.6.3)
 lifecycle     0.2.0   2020-03-06 [1] CRAN (R 3.6.3)
 listviewer  * 3.0.0   2019-11-02 [1] CRAN (R 3.6.3)
 magrittr      2.0.1   2020-11-17 [1] CRAN (R 3.6.3)
 mime          0.9     2020-02-04 [1] CRAN (R 3.6.2)
 packrat       0.5.0   2018-11-14 [1] CRAN (R 3.6.3)
 promises      1.1.1   2020-06-09 [1] CRAN (R 3.6.3)
 R6            2.5.0   2020-10-28 [1] CRAN (R 3.6.3)
 Rcpp          1.0.6   2021-01-15 [1] CRAN (R 3.6.3)
 rlang         0.4.10  2020-12-30 [1] CRAN (R 3.6.3)
 rstudioapi    0.13    2020-11-12 [1] CRAN (R 3.6.3)
 sass          0.3.1   2021-01-24 [1] CRAN (R 3.6.3)
 sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 3.6.3)
 shiny       * 1.6.0   2021-01-25 [1] CRAN (R 3.6.3)
 withr         2.4.1   2021-01-26 [1] CRAN (R 3.6.3)
 xtable        1.8-4   2019-04-21 [1] CRAN (R 3.6.3)
 yaml          2.2.1   2020-02-01 [1] CRAN (R 3.6.2)
@timelyportfolio
Copy link
Owner

Thanks for filing the issue. In hindsight, it probably was not a good idea to use .GlobalEnv in the example. I have provided an example below to illustrate the problem. Let me know if you need further clarification.

# works since all unnamed or all named
jsonedit(list(1,2,3)) # all unnamed
jsonedit(list(a=1,b=2,c=3)) # all named
# does not work since blend unnamed and named
jsonedit(list(a=1,2,3))

@kateodziomek
Copy link
Author

Thank you for responding so quickly! :)

Would you mind putting that it in a shiny context? I've used listviewer successfully before for quick, on the fly list browsing but never inside a shiny app.

I am still very new to shiny so full working examples are worth their wight in gold!

@timelyportfolio
Copy link
Owner

@kateodziomek Sure, here is how I would translate the example to a shiny context, and I have added a couple of other examples. There are many ways to achieve this same result, but I prefer the following approach.

Also, I have included a couple more examples https://github.com/timelyportfolio/listviewer/tree/master/inst/examples and https://github.com/timelyportfolio/listviewer/blame/master/README.md#L140-L166 if helpful.

library(shiny)
library(listviewer)

ui <- tagList(
  tags$div(
    style="display:flex;",
    jsoneditOutput("list1"),
    jsoneditOutput("list2"),
    jsoneditOutput("list3")
  ),
  tags$div(
    style="display:flex;",
    jsoneditOutput("list4"),
    jsoneditOutput("list5")
  )
)

server = function(input, output, session) {
  # works since all unnamed or all named
  j1 <- jsonedit(list(1,2,3)) # all unnamed
  j2 <- jsonedit(list(a=1,b=2,c=3)) # all named
  # does not work since blend unnamed and named
  #j3 <- jsonedit(list(a=1,2,3))
  
  j4 <- jsonedit(mtcars)
  j5 <- jsonedit(jsonlite::toJSON(mtcars, dataframe="rows"))
  
  output$list1 <- renderJsonedit({j1})
  output$list2 <- renderJsonedit({j2})
  #output$list3 <- renderJsonedit({j3})
  
  output$list4 <- renderJsonedit({j4})
  output$list5 <- renderJsonedit({j5})
}

shinyApp(ui, server)

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

No branches or pull requests

2 participants