Skip to content

Commit 3de353e

Browse files
authored
Rename ui_toolkit to ui and import it from the top-level (#63)
1 parent 2c68918 commit 3de353e

30 files changed

+151
-208
lines changed

examples/bind_event/app.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import asyncio
2-
import shiny.ui_toolkit as st
32
from shiny import *
43
from htmltools import tags
54

6-
ui = st.page_fluid(
5+
app_ui = ui.page_fluid(
76
tags.p(
87
"""
98
The first time you click the button, you should see a 1 appear below the button,
@@ -12,16 +11,16 @@
1211
print the number of clicks in the console twice.
1312
"""
1413
),
15-
st.navs_tab_card(
16-
st.nav(
14+
ui.navs_tab_card(
15+
ui.nav(
1716
"Sync",
18-
st.input_action_button("btn", "Click me"),
19-
st.output_ui("btn_value"),
17+
ui.input_action_button("btn", "Click me"),
18+
ui.output_ui("btn_value"),
2019
),
21-
st.nav(
20+
ui.nav(
2221
"Async",
23-
st.input_action_button("btn_async", "Click me"),
24-
st.output_ui("btn_async_value"),
22+
ui.input_action_button("btn_async", "Click me"),
23+
ui.output_ui("btn_async_value"),
2524
),
2625
),
2726
)
@@ -80,4 +79,4 @@ async def btn_async_value():
8079
return str(val)
8180

8281

83-
app = App(ui, server, debug=True)
82+
app = App(app_ui, server, debug=True)

examples/download/app.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
# To run this app:
2-
# python3 app.py
3-
4-
# Then point web browser to:
5-
# http://localhost:8000/
61
import asyncio
72
import os
83
import io
94
from datetime import date
105
from typing import Any
116

12-
import shiny.ui_toolkit as st
137
from shiny import *
14-
from htmltools import *
8+
from htmltools import div, p
159

1610
import matplotlib.pyplot as plt
1711
import numpy as np
1812

1913

2014
def make_example(id: str, label: str, title: str, desc: str, extra: Any = None):
21-
return st.column(
15+
return ui.column(
2216
4,
2317
div(
2418
{"class": "card mb-4"},
@@ -27,50 +21,50 @@ def make_example(id: str, label: str, title: str, desc: str, extra: Any = None):
2721
{"class": "card-body"},
2822
p(desc, class_="card-text text-muted"),
2923
extra,
30-
st.download_button(id, label, class_="btn-primary"),
24+
ui.download_button(id, label, class_="btn-primary"),
3125
),
3226
),
3327
)
3428

3529

36-
ui = st.page_fluid(
37-
st.row(
30+
app_ui = ui.page_fluid(
31+
ui.row(
3832
make_example(
3933
"download1",
4034
label="Download CSV",
4135
title="Simple case",
4236
desc="Downloads a pre-existing file, using its existing name on disk.",
4337
),
4438
),
45-
st.row(
39+
ui.row(
4640
make_example(
4741
"download2",
4842
label="Download plot",
4943
title="Dynamic data generation",
5044
desc="Downloads a PNG that's generated on the fly.",
5145
extra=[
52-
st.input_text("title", "Plot title", "Random scatter plot"),
53-
st.input_slider("num_points", "Number of data points", 1, 100, 50),
46+
ui.input_text("title", "Plot title", "Random scatter plot"),
47+
ui.input_slider("num_points", "Number of data points", 1, 100, 50),
5448
],
5549
),
5650
),
57-
st.row(
51+
ui.row(
5852
make_example(
5953
"download3",
6054
"Download",
6155
"Dynamic filename",
6256
"Demonstrates that filenames can be generated on the fly (and use Unicode characters!).",
6357
),
6458
),
65-
st.row(
59+
ui.row(
6660
make_example(
6761
"download4",
6862
"Download",
6963
"Failed downloads",
7064
"Throws an error in the download handler, download should not succeed.",
7165
),
7266
),
73-
st.row(
67+
ui.row(
7468
make_example(
7569
"download5",
7670
"Download",
@@ -126,4 +120,4 @@ async def _():
126120
raise Exception("This error was caused intentionally")
127121

128122

129-
app = App(ui, server)
123+
app = App(app_ui, server)

examples/dynamic_ui/app.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
1-
# To run this app:
2-
# python3 app.py
3-
4-
# Then point web browser to:
5-
# http://localhost:8000/
6-
7-
import shiny.ui_toolkit as st
81
from shiny import *
9-
from htmltools import *
2+
from htmltools import tags
103

114
# For plot rendering
125
import numpy as np
136
import matplotlib.pyplot as plt
147

15-
ui = st.page_fluid(
16-
st.layout_sidebar(
17-
st.panel_sidebar(
18-
st.h2("Dynamic UI"),
19-
st.output_ui("ui"),
20-
st.input_action_button("btn", "Trigger insert/remove ui"),
8+
app_ui = ui.page_fluid(
9+
ui.layout_sidebar(
10+
ui.panel_sidebar(
11+
ui.h2("Dynamic UI"),
12+
ui.output_ui("ui"),
13+
ui.input_action_button("btn", "Trigger insert/remove ui"),
2114
),
22-
st.panel_main(
23-
st.output_text_verbatim("txt"),
24-
st.output_plot("plot"),
15+
ui.panel_main(
16+
ui.output_text_verbatim("txt"),
17+
ui.output_plot("plot"),
2518
),
2619
),
2720
)
@@ -50,10 +43,10 @@ def plot():
5043
ax.hist(x, input.n(), density=True)
5144
return fig
5245

53-
@output()
46+
@output(name="ui")
5447
@render_ui()
55-
def ui():
56-
return st.input_slider(
48+
def _():
49+
return ui.input_slider(
5750
"This slider is rendered via @render_ui()", "N", 0, 100, 20
5851
)
5952

@@ -66,4 +59,4 @@ def _():
6659
ui_remove("#thanks")
6760

6861

69-
app = App(ui, server)
62+
app = App(app_ui, server)

0 commit comments

Comments
 (0)