You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
R version 4.4.1 (2024-06-14 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 10 x64 (build 19045)
Matrix products: default
locale:
[1] LC_COLLATE=Finnish_Finland.utf8 LC_CTYPE=Finnish_Finland.utf8 LC_MONETARY=Finnish_Finland.utf8 LC_NUMERIC=C LC_TIME=Finnish_Finland.utf8
time zone: Europe/Helsinki
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] shiny_1.9.1
loaded via a namespace (and not attached):
[1] digest_0.6.37 later_1.4.1 R6_2.5.1 httpuv_1.6.15 fastmap_1.2.0 magrittr_2.0.3 htmltools_0.5.8.1 lifecycle_1.0.4 promises_1.3.2 cli_3.6.3
[11] xtable_1.8-4 compiler_4.4.1 rstudioapi_0.17.1 tools_4.4.1 mime_0.12 Rcpp_1.0.13-1 rlang_1.1.4
Example application or steps to reproduce the problem
library("shiny")
ui<- fluidPage(
uiOutput("selectize"),
verbatimTextOutput('row'),
title='Using options groups for server-side selectize input'
)
server<-function(input, output, session) {
rv<- reactiveValues(init=FALSE)
observe({
rv$init<-FALSETitanic2<- as.data.frame(Titanic, stringsAsFactors=FALSE)
Titanic2<- cbind(Titanic2, value= seq_len(nrow(Titanic2)))
Titanic2$label<- apply(Titanic2[, 2:4], 1, paste, collapse=', ')
updateSelectizeInput(
session,
'group',
choices=NULL
)
updateSelectizeInput(
session,
'group',
choices=Titanic2,
options=list(
placeholder='Select a category',
# predefine all option groupsoptgroups=list(
list(value='1st', label='First Class'),
list(value='2nd', label='Second Class'),
list(value='3rd', label='Third Class'),
list(value='Crew', label='Crew')
),
# 'Class' is a field in Titanic2 created in server.RoptgroupField='Class',
optgroupOrder= c('1st', '2nd', '3rd', 'Crew'),
# you can type and search in these fields in Titanic2searchField= c('Sex', 'Age', 'Survived'),
# how to render the options (each item is a row in Titanic2)render= I("{ option: function(item, escape) { return '<div>' + escape(item.Age) + ' (' + (item.Sex == 'Male' ? '♂' : '♀') + ', ' + (item.Survived == 'Yes' ? '♥' : '⊝') + ')' + '</div>'; } }"
)
),
server=TRUE
)
})
output$row<- renderPrint({
validate(need(
input$group, 'Please type and search (e.g. Female)'
))
})
output$selectize<- renderUI({
rv$init<-TRUE
selectizeInput('group', label="Label", choices=NA)
})
}
shinyApp(ui=ui, server=server)
Describe the problem in detail
I'm trying to create a dynamically generated selectizeInput with optgroups (based on this example https://github.com/rstudio/shiny-examples/tree/main/023-optgroup-server). If the initial choices is not NULL, updateSelectizeInput creates a strange additional undefined option at the top of the list:
If instead choices is initially NULL, this option does not appear:
I would expect the initial choices to be cleared by the update despite the initial values, but this does not seem to be the case.
The text was updated successfully, but these errors were encountered:
santikka
changed the title
updateSelectizeInpute does not properly clear existing choicesupdateSelectizeInput does not properly clear existing choicesDec 10, 2024
System details
Output of
sessionInfo()
:Example application or steps to reproduce the problem
Describe the problem in detail
I'm trying to create a dynamically generated
selectizeInput
withoptgroups
(based on this example https://github.com/rstudio/shiny-examples/tree/main/023-optgroup-server). If the initialchoices
is notNULL
,updateSelectizeInput
creates a strange additional undefined option at the top of the list:If instead
choices
is initiallyNULL
, this option does not appear:I would expect the initial
choices
to be cleared by the update despite the initial values, but this does not seem to be the case.The text was updated successfully, but these errors were encountered: