Agenda
Introduction to shiny modules
Including reactivity in your module
A shiny module provides you with a way to encapsulate both:
This allows you to:
This is:
Create a shiny module:
from shiny express import input, output, session, module
@module
def card_module(input, output, session, title, fn):
with ui.card():
ui.card_header(title)
@render.plot
def _plot_out():
return fn()Call the module like you call a function:
Important
input, output or session to the moduleid that must be unique in the namespaceCreate a shiny module:
Call the module like you call a function:
Agenda
Introduction to shiny modules
Including reactivity in your module
lambda functionsDefine a module:
@module
def card_module(input, output, session, title, fn):
with ui.card():
ui.card_header(title)
@render.plot
def _plot_out():
return fn()Calling it like this throws an error:
Important
RuntimeError: No current reactive context
no current reactive context errorPython performs eager evaluation.
This means that plots.temp_distribution() gets evaluated when the card_module is instantiated.
But you need to delay this evaluation until the shiny app needs to render the value.
no current reactive context errorPython evaluation is eager.
But you can delay evaluation to be lazy using a lambda inline function: