shiny
shiny copied to clipboard
SelectizeInput selection cannot be updated beyond 1000
I'm not sure if this is a bug with selectize.js or shiny, but the updateSelectizeInput()
cannot receive a value higher than 1000 for selected
.
I use a numericInput
to update the selected
value of a selectizeInput
. When the value goes beyond 1000, the selectizeInput
is blank, and there are no error message in the browser console or the R session.
But the data is completely available from the selectizeInput
, which can be verified by typing 1001
in the selectizeInput
.
library(shiny)
library(tidyverse)
# Create a long dataset
data <- tibble(
sentence = stringr::sentences,
token = str_split(sentence, "\\s+")
) %>%
unnest(token) %>%
mutate(
id = row_number()
)
ui <- fluidPage(
mainPanel(
selectizeInput("selector", "Select", choices = ""),
numericInput("value_selector", label = NULL, value = 1000),
)
)
server <- function(input, output, session) {
updateSelectizeInput(
session, 'selector',
server = TRUE,
selected = 1,
choices = data,
options = list(
labelField = "token",
searchField = list("token", "id"),
valueField = "id",
render = I(
"{
option: function(item, escape) {
return '<div><strong>' + escape(item.token) +'</strong> (' + item.id + ')</div>';
}
}"))
)
observeEvent(input$value_selector, {
updateSelectizeInput(session, "selector", selected = input$value_selector)
})
}
shinyApp(ui = ui, server = server)
System details
Browser Version: Chrome
Output of `sessionInfo()`:
R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.5 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
[4] 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
[10] 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] forcats_0.5.1 stringr_1.4.0 dplyr_1.0.7 purrr_0.3.4 readr_2.1.1 tidyr_1.1.4
[7] tibble_3.1.6 ggplot2_3.3.5 tidyverse_1.3.1 shiny_1.7.1
loaded via a namespace (and not attached):
[1] bslib_0.3.1 tidyselect_1.1.1 haven_2.4.3 colorspace_2.0-2 vctrs_0.3.8 generics_0.1.1
[7] htmltools_0.5.2 utf8_1.2.2 rlang_0.4.12 jquerylib_0.1.4 later_1.3.0 pillar_1.6.4
[13] glue_1.5.1 withr_2.4.3 DBI_1.1.1 dbplyr_2.1.1 modelr_0.1.8 readxl_1.3.1
[19] lifecycle_1.0.1 munsell_0.5.0 gtable_0.3.0 cellranger_1.1.0 rvest_1.0.2 tzdb_0.2.0
[25] fastmap_1.1.0 httpuv_1.6.4 fansi_0.5.0 broom_0.7.10 Rcpp_1.0.7 xtable_1.8-4
[31] renv_0.13.2 promises_1.2.0.1 backports_1.4.1 scales_1.1.1 cachem_1.0.6 jsonlite_1.7.2
[37] mime_0.12 fs_1.5.2 hms_1.1.1 digest_0.6.29 stringi_1.7.6 grid_4.1.2
[43] cli_3.1.0 tools_4.1.2 sass_0.4.0 magrittr_2.0.1 crayon_1.4.2 pkgconfig_2.0.3
[49] ellipsis_0.3.2 xml2_1.3.3 reprex_2.0.1 lubridate_1.8.0 rstudioapi_0.13 assertthat_0.2.1
[55] httr_1.4.2 R6_2.5.1 compiler_4.1.2
<\details>
Details
When I discovered the bug initially, the max value was 962 instead of 1000, so it seems to fluctuate.
See here.
Thanks! That indeed solves my issue.
I still think there is a bug (or an undocumented behavior) because when server = TRUE
, maxOptions
controls the number of matching records displayed AND somehow, the maximum number of items that can be selected
if maxOptions
> 1000 this last part seems to be unintended, or at least undocumented.
Since most selectizeInput
are intended to be selected manually rather than programmatically, maybe this is a bug that doesn't need to be fixed. Or maybe a quick fix could be to set the default maxOptions = nrow(choices)
when server = TRUE
.
I don't think that maxOptions = nrow(choices)
would be a good solution here, since IIUC the benefit of doing server = TRUE
in the first place is avoiding having to send over a very large number of options to the client.