How do you initialise a ui.input_select
so that all items are initially selected when multiple=True
?
In my example belowdata.EQUIPMENT_TYPES
is a Tuple[str, ...]
but when I run my code sometimes I get all items selected, sometimes none and sometimes a subset. Setting multiple=False
and passing a single item for selected=
works fine, but not when both are (the same) tuple?
ui.sidebar(
ui.input_select(
"equipment_types",
"Equipment Types",
choices=data.EQUIPMENT_TYPES,
multiple=True,
selected=data.EQUIPMENT_TYPES,
selectize=True,
)
Hi,
Could you try and generate a reproducible example. A reprex consists of the minimal code and data needed to recreate the issue/question you're having.
In your case if I try to recreate it I have no issues
from shiny import App, Inputs, Outputs, Session, ui
sel = ["A", "B", "C"]
app_ui = ui.page_fluid(
ui.input_select("x", "Select", choices=sel, multiple = True, selected=sel),
)
def server(input: Inputs, output: Outputs, session: Session):
return
app = App(app_ui, server)
The only thing I can think of is to convert your tuple to a list and make sure that all the entries are strings, and not a combination of data types (e.g. integers, bool, etc).
Grtz,
PJ
Hi
Your example fails for me if I add selectize=True
to ui.input_select - i.e.
from shiny import App, Inputs, Outputs, Session, ui
sel = ["A", "B", "C"]
app_ui = ui.page_fluid(
ui.input_select("x", "Select", choices=sel, multiple=True, selected=sel, selectize=True),
)
def server(input: Inputs, output: Outputs, session: Session):
return
app = App(app_ui, server)
When the page first loads only B is selected (at least at the moment). I'm running on Ubuntu 22.04 using Firefox
Hello,
I don't have the issue when I run it with selectize=True as all are selected by default when I run the code. I am running this on a Windows machine though.
However, rather than an operating system cause, maybe it's related to the shiny version. Are you using shiny 1.0+?
>pip show shiny
Name: shiny
Version: 1.0.0
Grtz,
PJ
I'm using
shiny = "^1.1.0"
shinywidgets = "^0.3.3"
anywidget = "^0.9.13"
Hi,
I'm not sure I know what the cause might be, but one thing I would suggest is that you open your project on another machine and see if it has the same issue. If not, then it's operating system dependent (if all package versions are the same), if it is, then there might be something else in your code messing with it.
Maybe someone else will chime in too, but that's all I can think of for now
Grtz,
PJ