-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add busy indicators (aka spinners) (#918)
Co-authored-by: Carson <[email protected]>
- Loading branch information
Showing
43 changed files
with
521 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# pyright:basic | ||
import time | ||
|
||
import numpy as np | ||
import seaborn as sns | ||
|
||
from shiny import App, module, reactive, render, ui | ||
|
||
|
||
# -- Reusable card module -- | ||
@module.ui | ||
def card_ui(spinner_type): | ||
return ui.card( | ||
ui.busy_indicators.options(spinner_type=spinner_type), | ||
ui.card_header("Spinner: " + spinner_type), | ||
ui.output_plot("plot"), | ||
) | ||
|
||
|
||
@module.server | ||
def card_server(input, output, session, rerender): | ||
@render.plot | ||
def plot(): | ||
rerender() | ||
time.sleep(1) | ||
sns.lineplot(x=np.arange(100), y=np.random.randn(100)) | ||
|
||
|
||
# -- Main app -- | ||
app_ui = ui.page_fillable( | ||
ui.input_task_button("rerender", "Re-render"), | ||
ui.layout_columns( | ||
card_ui("ring", "ring"), | ||
card_ui("bars", "bars"), | ||
card_ui("dots", "dots"), | ||
card_ui("pulse", "pulse"), | ||
col_widths=6, | ||
), | ||
) | ||
|
||
|
||
def server(input, output, session): | ||
|
||
@reactive.calc | ||
def rerender(): | ||
return input.rerender() | ||
|
||
card_server("ring", rerender=rerender) | ||
card_server("bars", rerender=rerender) | ||
card_server("dots", rerender=rerender) | ||
card_server("pulse", rerender=rerender) | ||
|
||
|
||
app = App(app_ui, server) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import os | ||
import time | ||
|
||
import numpy as np | ||
import seaborn as sns | ||
|
||
from shiny import App, render, ui | ||
|
||
app_ui = ui.page_sidebar( | ||
ui.sidebar( | ||
ui.input_selectize( | ||
"indicator_types", | ||
"Busy indicator types", | ||
["spinners", "pulse"], | ||
multiple=True, | ||
selected=["spinners", "pulse"], | ||
), | ||
ui.download_button("download", "Download source"), | ||
), | ||
ui.card( | ||
ui.card_header( | ||
"Plot that takes a few seconds to render", | ||
ui.input_task_button("simulate", "Simulate"), | ||
class_="d-flex justify-content-between align-items-center", | ||
), | ||
ui.output_plot("plot"), | ||
), | ||
ui.busy_indicators.options(spinner_type="bars3"), | ||
ui.output_ui("indicator_types_ui"), | ||
title="Busy indicators demo", | ||
) | ||
|
||
|
||
def server(input): | ||
|
||
@render.plot | ||
def plot(): | ||
input.simulate() | ||
time.sleep(3) | ||
sns.lineplot(x=np.arange(100), y=np.random.randn(100)) | ||
|
||
@render.ui | ||
def indicator_types_ui(): | ||
return ui.busy_indicators.use( | ||
spinners="spinners" in input.indicator_types(), | ||
pulse="pulse" in input.indicator_types(), | ||
) | ||
|
||
@render.download | ||
def download(): | ||
time.sleep(3) | ||
path = os.path.join(os.path.dirname(__file__), "app-core.py") | ||
return path | ||
|
||
|
||
app = App(app_ui, server) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import os | ||
import time | ||
|
||
import numpy as np | ||
import seaborn as sns | ||
|
||
from shiny.express import input, render, ui | ||
|
||
ui.page_opts(title="Busy spinner demo") | ||
|
||
with ui.sidebar(): | ||
ui.input_selectize( | ||
"indicator_types", | ||
"Busy indicator types", | ||
["spinners", "pulse"], | ||
multiple=True, | ||
selected=["spinners", "pulse"], | ||
) | ||
|
||
@render.download | ||
def download(): | ||
time.sleep(3) | ||
path = os.path.join(os.path.dirname(__file__), "app-express.py") | ||
return path | ||
|
||
|
||
with ui.card(): | ||
ui.card_header( | ||
"Plot that takes a few seconds to render", | ||
ui.input_task_button("simulate", "Simulate"), | ||
class_="d-flex justify-content-between align-items-center", | ||
) | ||
|
||
@render.plot | ||
def plot(): | ||
input.simulate() | ||
time.sleep(3) | ||
sns.lineplot(x=np.arange(100), y=np.random.randn(100)) | ||
|
||
|
||
ui.busy_indicators.options(spinner_type="bars3") | ||
|
||
|
||
@render.ui | ||
def indicator_types_ui(): | ||
return ui.busy_indicators.use( | ||
spinners="spinners" in input.indicator_types(), | ||
pulse="pulse" in input.indicator_types(), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Generated by scripts/htmlDependencies.R: do not edit by hand | ||
|
||
from __future__ import annotations | ||
|
||
from typing import Literal | ||
|
||
BusySpinnerType = Literal[ | ||
"bars", | ||
"bars2", | ||
"bars3", | ||
"dots", | ||
"dots2", | ||
"dots3", | ||
"pulse", | ||
"pulse2", | ||
"pulse3", | ||
"ring", | ||
"ring2", | ||
"ring3", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.