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

sliderTextInput - character choices are being converted to numeric in JS #620

Open
tanho63 opened this issue Jul 27, 2023 · 0 comments
Open

Comments

@tanho63
Copy link

tanho63 commented Jul 27, 2023

The goal here is to update one sliderTextInput with values from another (in-real-app it's to keep one slider in sync with another),
and the values are numeric-like (i.e. character strings that look like numerics).

Reprex

library(shiny)
library(shinyWidgets)
choices <- format((1:50)/10,nsmall = 1)
# choices <- format((1:50)/10,nsmall = 1) |> paste0("M")
sel <- range(choices)
ui <- fluidPage(
  sliderTextInput('s1', label = "Slider", choices = choices, selected = sel),
  br(),
  sliderTextInput('s2', label = "Slider2", choices = choices, selected = sel),
  br(),
  actionButton("set", "set")
)

server <- function(input, output, session) {
  observeEvent(input$set,{
    updateSliderTextInput(session, inputId = "s2", selected = input$s1)
  })
}

shinyApp(ui, server)

If you press the button, the values from slider 1 do not properly get populated to slider 2. It seems like this is silently being converted to numeric in the backend - you can tell because it lost the decimal place on 5.0 and (I think) because this data-type="double" param on the input.

image

image

I've managed to work around this by pasting "M" to the end of the choices (i.e. uncomment other choices) and then remove the "M" server-side, but I imagine that this is an unintended bug.

Session Info
R> sessioninfo::session_info()
─ Session info ─────────────────────────────────────────────
 setting  value
 version  R version 4.2.0 (2022-04-22)
 os       Ubuntu 18.04.6 LTS
 system   x86_64, linux-gnu
 ui       RStudio
 language (EN)
 collate  C.UTF-8
 ctype    C.UTF-8
 tz       America/Los_Angeles
 date     2023-07-27
 rstudio  2022.07.0+548 Spotted Wakerobin (server)
 pandoc   NAPackages ─────────────────────────────────────────────────
 package      * version date (UTC) lib source
 bslib          0.5.0   2023-06-09 [1] CRAN (R 4.2.0)
 cachem         1.0.8   2023-05-01 [1] CRAN (R 4.2.0)
 callr          3.7.3   2022-11-02 [1] CRAN (R 4.2.0)
 cli            3.6.1   2023-03-23 [1] RSPM
 crayon         1.5.2   2022-09-29 [1] CRAN (R 4.2.0)
 devtools     * 2.4.5   2022-10-11 [1] CRAN (R 4.2.0)
 digest         0.6.33  2023-07-07 [1] CRAN (R 4.2.0)
 ellipsis       0.3.2   2021-04-29 [1] CRAN (R 4.2.0)
 fastmap        1.1.1   2023-02-24 [1] CRAN (R 4.2.0)
 fs             1.6.2   2023-04-25 [1] CRAN (R 4.2.0)
 glue           1.6.2   2022-02-24 [1] CRAN (R 4.2.0)
 htmltools      0.5.5   2023-03-23 [1] CRAN (R 4.2.0)
 htmlwidgets    1.6.2   2023-03-17 [1] CRAN (R 4.2.0)
 httpuv         1.6.11  2023-05-11 [1] CRAN (R 4.2.0)
 jquerylib      0.1.4   2021-04-26 [1] CRAN (R 4.2.0)
 jsonlite       1.8.7   2023-06-29 [1] CRAN (R 4.2.0)
 later          1.3.1   2023-05-02 [1] CRAN (R 4.2.0)
 lifecycle      1.0.3   2022-10-07 [1] CRAN (R 4.2.0)
 magrittr       2.0.3   2022-03-30 [1] CRAN (R 4.2.0)
 memoise        2.0.1   2021-11-26 [1] CRAN (R 4.2.0)
 mime           0.12    2021-09-28 [1] CRAN (R 4.2.0)
 miniUI         0.1.1.1 2018-05-18 [1] CRAN (R 4.2.0)
 pkgbuild       1.3.1   2021-12-20 [2] RSPM (R 4.2.0)
 pkgload        1.3.2.1 2023-07-08 [1] CRAN (R 4.2.0)
 prettyunits    1.1.1   2020-01-24 [1] CRAN (R 4.2.0)
 processx       3.8.2   2023-06-30 [1] CRAN (R 4.2.0)
 profvis        0.3.7   2020-11-02 [1] CRAN (R 4.2.0)
 promises       1.2.0.1 2021-02-11 [1] CRAN (R 4.2.0)
 ps             1.7.5   2023-04-18 [1] CRAN (R 4.2.0)
 purrr          1.0.1   2023-01-10 [1] CRAN (R 4.2.0)
 R6             2.5.1   2021-08-19 [1] CRAN (R 4.2.0)
 Rcpp           1.0.11  2023-07-06 [1] CRAN (R 4.2.0)
 remotes        2.4.2   2021-11-30 [1] CRAN (R 4.2.0)
 rlang          1.1.1   2023-04-28 [1] CRAN (R 4.2.0)
 rsconnect      0.8.27  2022-07-12 [2] RSPM (R 4.2.0)
 rstudioapi     0.14    2022-08-22 [1] CRAN (R 4.2.0)
 sass           0.4.7   2023-07-15 [1] CRAN (R 4.2.0)
 sessioninfo    1.2.2   2021-12-06 [1] CRAN (R 4.2.0)
 shiny        * 1.7.4.1 2023-07-06 [1] CRAN (R 4.2.0)
 shinyWidgets * 0.7.6   2023-01-08 [1] CRAN (R 4.2.0)
 stringi        1.7.12  2023-01-11 [1] CRAN (R 4.2.0)
 stringr        1.5.0   2022-12-02 [1] CRAN (R 4.2.0)
 urlchecker     1.0.1   2021-11-30 [1] CRAN (R 4.2.0)
 usethis      * 2.1.6   2022-05-25 [1] CRAN (R 4.2.0)
 vctrs          0.6.3   2023-06-14 [1] CRAN (R 4.2.0)
 xtable         1.8-4   2019-04-21 [1] CRAN (R 4.2.0)

 [1] /home/tan/R/x86_64-pc-linux-gnu-library/4.2
 [2] /usr/local/lib/R/site-library
 [3] /usr/lib/R/site-library
 [4] /usr/lib/R/library

────────────────────────────────────────────────────────────
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

1 participant