Skip to content

Commit b6451fd

Browse files
authored
Change express.layout to express.ui (#904)
1 parent 9d02ef9 commit b6451fd

File tree

25 files changed

+2204
-1056
lines changed

25 files changed

+2204
-1056
lines changed

docs/_quartodoc.yml

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -283,26 +283,43 @@ quartodoc:
283283
- title: Shiny Express
284284
desc: Functions for Shiny Express applications
285285
contents:
286-
- express.layout.set_page
287-
- express.layout.p
288-
- express.layout.div
289-
- express.layout.span
290-
- express.layout.pre
291-
- express.layout.sidebar
292-
- express.layout.layout_columns
293-
- express.layout.layout_column_wrap
294-
- express.layout.column
295-
- express.layout.row
296-
- express.layout.card
297-
- express.layout.accordion
298-
- express.layout.accordion_panel
299-
- express.layout.navset
300-
- express.layout.navset_card
301-
- express.layout.nav_panel
302-
- express.layout.page_fluid
303-
- express.layout.page_fixed
304-
- express.layout.page_fillable
305-
- express.layout.page_sidebar
286+
- kind: page
287+
path: ContextManagerComponents
288+
summary:
289+
name: "Context manager components"
290+
desc: ""
291+
flatten: true
292+
contents:
293+
- express.ui.set_page
294+
- express.ui.sidebar
295+
- express.ui.layout_sidebar
296+
- express.ui.layout_column_wrap
297+
- express.ui.layout_columns
298+
- express.ui.card
299+
- express.ui.accordion
300+
- express.ui.accordion_panel
301+
- express.ui.nav_panel
302+
- express.ui.nav_control
303+
- express.ui.nav_menu
304+
- express.ui.navset_bar
305+
- express.ui.navset_card_pill
306+
- express.ui.navset_card_tab
307+
- express.ui.navset_card_underline
308+
- express.ui.navset_hidden
309+
- express.ui.navset_pill
310+
- express.ui.navset_pill_list
311+
- express.ui.navset_tab
312+
- express.ui.navset_underline
313+
- express.ui.value_box
314+
- express.ui.panel_well
315+
- express.ui.panel_conditional
316+
- express.ui.panel_fixed
317+
- express.ui.panel_absolute
318+
- express.ui.page_fluid
319+
- express.ui.page_fixed
320+
- express.ui.page_fillable
321+
- express.ui.page_sidebar
322+
- express.ui.page_navbar
306323
- title: Deprecated
307324
desc: ""
308325
contents:

examples/express/accordion_app.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import matplotlib.pyplot as plt
22
import numpy as np
33

4-
from shiny import render, ui
5-
from shiny.express import input, layout
4+
from shiny import render
5+
from shiny.express import input, ui
66

7-
with layout.accordion(open=["Panel 1", "Panel 2"]):
8-
with layout.accordion_panel("Panel 1"):
7+
with ui.accordion(open=["Panel 1", "Panel 2"]):
8+
with ui.accordion_panel("Panel 1"):
99
ui.input_slider("n", "N", 1, 100, 50)
1010

11-
with layout.accordion_panel("Panel 2"):
11+
with ui.accordion_panel("Panel 2"):
1212

1313
@render.text
1414
def txt():

examples/express/basic_app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from shiny import render, ui
2-
from shiny.express import input
1+
from shiny import render
2+
from shiny.express import input, ui
33

44
ui.input_slider("n", "N", 1, 100, 50)
55

examples/express/column_wrap_app.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import matplotlib.pyplot as plt
22
import numpy as np
33

4-
from shiny import render, ui
5-
from shiny.express import input, layout
4+
from shiny import render
5+
from shiny.express import input, ui
66

7-
with layout.layout_column_wrap(width=1 / 2):
8-
with layout.card():
7+
with ui.layout_column_wrap(width=1 / 2):
8+
with ui.card():
99
ui.input_slider("n", "N", 1, 100, 50)
1010

11-
with layout.card():
11+
with ui.card():
1212

1313
@render.plot
1414
def histogram():
1515
np.random.seed(19680801)
1616
x = 100 + 15 * np.random.randn(437)
1717
plt.hist(x, input.n(), density=True)
1818

19-
with layout.card():
19+
with ui.card():
2020

2121
@render.plot
2222
def histogram2():

examples/express/nav_app.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
import matplotlib.pyplot as plt
22
import numpy as np
33

4-
from shiny import render, ui
5-
from shiny.express import input, layout
4+
from shiny import render
5+
from shiny.express import input, ui
66

7-
with layout.layout_column_wrap(width=1 / 2):
8-
with layout.navset():
9-
with layout.nav_panel(title="One"):
7+
with ui.layout_column_wrap(width=1 / 2):
8+
with ui.navset_underline():
9+
with ui.nav_panel(title="One"):
1010
ui.input_slider("n", "N", 1, 100, 50)
1111

12-
with layout.nav_panel(title="Two"):
12+
with ui.nav_panel(title="Two"):
1313

1414
@render.plot
1515
def histogram():
1616
np.random.seed(19680801)
1717
x = 100 + 15 * np.random.randn(437)
1818
plt.hist(x, input.n(), density=True)
1919

20-
with layout.navset_card():
21-
with layout.nav_panel(title="One"):
20+
with ui.navset_card_underline():
21+
with ui.nav_panel(title="One"):
2222
ui.input_slider("n2", "N", 1, 100, 50)
2323

24-
with layout.nav_panel(title="Two"):
24+
with ui.nav_panel(title="Two"):
2525

2626
@render.plot
2727
def histogram2():

examples/express/shared_app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import numpy as np
77
import shared
88

9-
from shiny import reactive, render, ui
10-
from shiny.express import input
9+
from shiny import reactive, render
10+
from shiny.express import input, ui
1111

1212

1313
@render.plot

examples/express/sidebar_app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import matplotlib.pyplot as plt
22
import numpy as np
33

4-
from shiny import render, ui
5-
from shiny.express import input, layout
4+
from shiny import render
5+
from shiny.express import input, ui
66

7-
with layout.sidebar():
7+
with ui.sidebar():
88
ui.input_slider("n", "N", 1, 100, 50)
99

1010

shiny/express/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from ..session import Inputs, Outputs, Session
44
from ..session import _utils as _session_utils
5-
from . import app, layout
5+
from . import app, ui
66
from ._is_express import is_express_app
77
from ._output import output_args, suspend_display
88
from ._run import wrap_express_app
@@ -17,7 +17,7 @@
1717
"suspend_display",
1818
"wrap_express_app",
1919
"app",
20-
"layout",
20+
"ui",
2121
"display_body",
2222
)
2323

shiny/express/_recall_context.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from types import TracebackType
66
from typing import Callable, Generic, Mapping, Optional, Type, TypeVar
77

8-
from htmltools import Tag, wrap_displayhook_handler
8+
from htmltools import MetadataNode, Tag, TagList, wrap_displayhook_handler
99

1010
from .._typing_extensions import ParamSpec
1111

@@ -54,6 +54,19 @@ def __exit__(
5454
sys.displayhook(res)
5555
return False
5656

57+
def tagify(self) -> Tag | TagList | MetadataNode | str:
58+
res = self.fn(*self.args, **self.kwargs)
59+
60+
if callable(getattr(res, "tagify", None)):
61+
return res.tagify() # pyright: ignore
62+
if callable(getattr(res, "_repr_html_", None)):
63+
return res._repr_html_() # pyright: ignore
64+
65+
raise RuntimeError(
66+
"RecallContextManager was used without `with`. When used this way, the "
67+
"result must have a .tagify() or ._repr_html_() method, but it does not."
68+
)
69+
5770

5871
def wrap_recall_context_manager(
5972
fn: Callable[P, R]

0 commit comments

Comments
 (0)