Open
Description
Here's a minimal example:
import time
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
from shiny import App, Inputs, Outputs, Session, reactive, render, ui
app_ui = ui.page_fluid(
ui.input_slider(
"n", "input_slider()", min=10, max=100, value=50, step=5, animate=True
),
ui.input_task_button("do_plot", "Do plot"),
ui.output_plot("p"),
)
def server(input: Inputs, output: Outputs, session: Session):
def do_plot():
time.sleep(0.5)
# Without ax, seaborn works through side effects, so supply the ax to avoid
# one figure from affecting another.
fig, ax = plt.subplots(1, 1)
sns.lineplot(x=np.arange(100), y=np.random.randn(100), ax=ax)
return fig
@ui.bind_task_button(button_id="do_plot")
@reactive.extended_task
async def plot_task():
return do_plot()
@reactive.effect
@reactive.event(do_plot)
def _():
plot_task()
@render.plot
def p():
return plot_task.result()
app = App(app_ui, server)
zoom-on-resize.mp4
Metadata
Metadata
Assignees
Labels
No labels