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

numericInput() returns 0 instead of NA #3674

Closed
hcstubbe opened this issue Jul 18, 2022 · 4 comments
Closed

numericInput() returns 0 instead of NA #3674

hcstubbe opened this issue Jul 18, 2022 · 4 comments

Comments

@hcstubbe
Copy link

hcstubbe commented Jul 18, 2022

When using the latest version of R (4.2.0 or 4.2.1, both on Windows 11 or Ubuntu 20.04.4 LTS), the numericInput() returns 0 instead of NA, when no value or a string are entered, if DT::renderDT() is used to render a table.

I also referenced this problem here.

System details

Output of sessionInfo() (Windows 11 and Ubuntu 20.04.4 LTS):

Ubuntu 20.04.4 LTS:

R version 4.2.0 (2022-04-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.4 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] shiny_1.7.1 lcarsc_0.2 

loaded via a namespace (and not attached):
 [1] whoami_1.3.0         fs_1.5.2             xopen_1.0.0          usethis_2.1.6        lubridate_1.8.0      fontawesome_0.2.2    devtools_2.4.3       bit64_4.0.5         
 [9] httr_1.4.3           rprojroot_2.0.3      tools_4.2.0          bslib_0.3.1          utf8_1.2.2           R6_2.5.1             DT_0.23              DBI_1.1.3           
[17] withr_2.5.0          tidyselect_1.1.2     prettyunits_1.1.1    shinyvalidate_0.1.2  processx_3.7.0       rematch_1.0.1        bit_4.0.4            curl_4.3.2          
[25] compiler_4.2.0       cli_3.3.0            xml2_1.3.3           shinyjs_2.1.0        desc_1.4.1           sass_0.4.1           readr_2.1.2          callr_3.7.1         
[33] rappdirs_0.3.3       stringr_1.4.0        digest_0.6.29        pkgconfig_2.0.3      htmltools_0.5.2      sessioninfo_1.2.2    attempt_0.3.1        fastmap_1.1.0       
[41] htmlwidgets_1.5.4    rlang_1.0.4          RMariaDB_1.2.2       rstudioapi_0.13      RSQLite_2.2.14       jquerylib_0.1.4      generics_0.1.3       jsonlite_1.8.0      
[49] crosstalk_1.2.0      dplyr_1.0.9          config_0.3.1         magrittr_2.0.3       Rcpp_1.0.9           fansi_1.0.3          lifecycle_1.0.1      stringi_1.7.8       
[57] yaml_2.3.5           brio_1.1.3           pkgbuild_1.3.1       blob_1.2.3           promises_1.2.0.1     shinydashboard_0.7.2 crayon_1.5.1         rhub_1.1.1          
[65] hms_1.1.1            knitr_1.39           parsedate_1.3.0      ps_1.7.1             pillar_1.7.0         uuid_1.1-0           pkgload_1.3.0        glue_1.6.2          
[73] golem_0.3.3          pool_0.1.6           remotes_2.4.2        fmsb_0.7.3           vctrs_0.4.1          tzdb_0.3.0           httpuv_1.6.5         testthat_3.1.4      
[81] purrr_0.3.4          rcmdcheck_1.4.0      assertthat_0.2.1     cachem_1.0.6         xfun_0.31            mime_0.12            xtable_1.8-4         roxygen2_7.2.0      
[89] later_1.3.0          tibble_3.1.7         memoise_2.0.1        shinyWidgets_0.7.1   ellipsis_0.3.2    

Windows 11:

R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.utf8  LC_CTYPE=German_Germany.utf8    LC_MONETARY=German_Germany.utf8 LC_NUMERIC=C                    LC_TIME=German_Germany.utf8    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] DT_0.23     shiny_1.7.1

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9        digest_0.6.29     later_1.3.0       mime_0.12         R6_2.5.1          jsonlite_1.8.0    lifecycle_1.0.1   xtable_1.8-4     
 [9] magrittr_2.0.3    cachem_1.0.6      rlang_1.0.3       promises_1.2.0.1  jquerylib_0.1.4   bslib_0.4.0       ellipsis_0.3.2    tools_4.2.1      
[17] htmlwidgets_1.5.4 crosstalk_1.2.0   yaml_2.3.5        httpuv_1.6.5      fastmap_1.1.0     compiler_4.2.1    memoise_2.0.1     htmltools_0.5.2  
[25] sass_0.4.1   

Example application

After launching the application delete the input or enter a character.

if (interactive()) {
library(shiny)
library(DT)
ui <- fluidPage(
    numericInput("obs", "Observations:", 10, min = 1, max = 100),
    verbatimTextOutput("value"),
    DT::dataTableOutput("responses_table")
)
server <- function(input, output) {
    output$value <- renderText({ input$obs })
    
    output$responses_table <- DT::renderDT({
        isolate(DT::datatable(iris)
        )
    })
    
}
shinyApp(ui, server)
}

Describe the problem in detail

When using the latest version of R (4.2.0 or 4.2.1, both on Windows 11 or Ubuntu 20.04.4 LTS), the numericInput() returns 0 instead of NA, when no value or a string are entered, if DT::renderDT() is used to render a table. I tested this for the latest R version (4.2.0 and 4.2.1) and on Ubuntu and Windows (see above). This problem is absent in older R versions (e.g. R version 4.1.2). In a data app, where empty values need to be represented as NA, this is a huge problem.

@jcheng5
Copy link
Member

jcheng5 commented Jul 18, 2022

Thanks for the report. Some clarifying questions:

  1. When you say it's 0 instead of NA, do you mean that 0 is shown in verbatimTextOutput("value")?
  2. If you remove the DT from the app, does it change the behavior of the text output?

@hcstubbe
Copy link
Author

hcstubbe commented Jul 18, 2022

Hi, thank you for getting back to me!

  1. input$obs returns 0 instead of NA. Therefore, 0 is shown instead of NA in verbatimTextOutput("value").
  2. If I remove DT from the app, the problem disappears: input$obs can return NA again.

EDIT:
simply adding DT::datatable(iris) to the ui changes the behavior of the numericInput() (the code is the example from ?numericInput ):


## Only run examples in interactive R sessions
if (interactive()) {
    
    ui <- fluidPage(
        numericInput("obs", "Observations:", 10, min = 1, max = 100),
        verbatimTextOutput("value"),
        DT::datatable(iris)  # This line changes the behavior of numericInput()
    )
    server <- function(input, output) {
        output$value <- renderText({ input$obs })
    }
    shinyApp(ui, server)
}


@jcheng5
Copy link
Member

jcheng5 commented Jul 19, 2022

Wow, confirmed on Windows 10, R 4.2.0. Exactly as you said--without the DT, no issue. And it doesn't happen on macOS R 4.1.2. What in the world??

@jcheng5
Copy link
Member

jcheng5 commented Jul 19, 2022

OK, mystery solved. It's an issue in DT that has since been fixed, but not yet released on CRAN. If you remotes::install_github("rstudio/DT"), you should be good.

@jcheng5 jcheng5 closed this as completed Jul 19, 2022
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