render_ipyfilechooser
render_ipyfilechooser class
Reactively render an ipyfilechooser file chooser.
Usage Source
render_ipyfilechooser(
_fn: Optional[ValueFn[ValueT]] = None,
*,
width: Optional[str] = None,
height: Optional[str] = None,
fill: Optional[bool] = None,
fillable: Optional[bool] = None,
rate_policy: Optional[RatePolicy] = None,
rate_delay: Optional[float] = None,
)@render_ipyfilechooser is a decorator that creates a render function – a function that returns the chooser to display and re-runs when the reactive values it reads change:
from ipyfilechooser import FileChooser
from shinywidgets import render_ipyfilechooser
@render_ipyfilechooser
def chooser():
return FileChooser()The render function should return an ipyfilechooser.FileChooser widget (requires pip install 'shinywidgets[ipyfilechooser]'). The chooser is a form control with a natural size, so the output doesn’t fill its container; size it with the chooser’s own layout (e.g., layout=Layout(width='700px')) or with output_widget(width=..., height=...).
Note
Accessing the rendered widget: the render function gains two read-only attributes: .value, the value it most recently returned, and .widget, the rendered FileChooser instance. Note that the chooser’s selected, selected_path and selected_filename are plain Python properties (not widget traits), so they can’t be read with reactive_read().
Responding to user interaction: to react to a selection, pass .widget.register_callback() a function that sets a reactive.value (the callback fires when the user confirms or changes a selection).
Mutating the widget: this renderer documents no in-place updates; change the chooser’s constructor arguments and re-render.
Parameters
width : Optional[str] = None-
A CSS length unit (e.g.,
"400px"or"100%") for the output’s width. height : Optional[str] = None-
A CSS length unit for the output’s height. When
None(the default), the output is designed to fill the height of its parent container (seefillandfillable). fill : Optional[bool] = None-
Whether the output should grow or shrink to fit its parent container. When
None(the default), this isTrueifheightis not specified. fillable : Optional[bool] = None-
Whether the output container should fill available space (scrolling its contents on overflow). When
None(the default), this isTrueifheightis not specified.
Examples
from ipyfilechooser import FileChooser
from shiny import App, reactive, render, ui
from shinywidgets import output_widget, render_ipyfilechooser
app_ui = ui.page_fluid(
output_widget("chooser"),
ui.output_text("selected"),
)
def server(input, output, session):
selection = reactive.value(None)
@render_ipyfilechooser
def chooser():
fc = FileChooser()
fc.register_callback(lambda fc: selection.set(fc.selected))
return fc
@render.text
def selected():
return f"Selected: {selection()}"
app = App(app_ui, server)See also
output_widget(): in Shiny Core, the UI needs this to hold the output (Shiny Express displays it where the render function is defined).