Skip to content

Commit

Permalink
Change express.layout to express.ui (#904)
Browse files Browse the repository at this point in the history
  • Loading branch information
wch authored Dec 21, 2023
1 parent 9d02ef9 commit b6451fd
Show file tree
Hide file tree
Showing 25 changed files with 2,204 additions and 1,056 deletions.
57 changes: 37 additions & 20 deletions docs/_quartodoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -283,26 +283,43 @@ quartodoc:
- title: Shiny Express
desc: Functions for Shiny Express applications
contents:
- express.layout.set_page
- express.layout.p
- express.layout.div
- express.layout.span
- express.layout.pre
- express.layout.sidebar
- express.layout.layout_columns
- express.layout.layout_column_wrap
- express.layout.column
- express.layout.row
- express.layout.card
- express.layout.accordion
- express.layout.accordion_panel
- express.layout.navset
- express.layout.navset_card
- express.layout.nav_panel
- express.layout.page_fluid
- express.layout.page_fixed
- express.layout.page_fillable
- express.layout.page_sidebar
- kind: page
path: ContextManagerComponents
summary:
name: "Context manager components"
desc: ""
flatten: true
contents:
- express.ui.set_page
- express.ui.sidebar
- express.ui.layout_sidebar
- express.ui.layout_column_wrap
- express.ui.layout_columns
- express.ui.card
- express.ui.accordion
- express.ui.accordion_panel
- express.ui.nav_panel
- express.ui.nav_control
- express.ui.nav_menu
- express.ui.navset_bar
- express.ui.navset_card_pill
- express.ui.navset_card_tab
- express.ui.navset_card_underline
- express.ui.navset_hidden
- express.ui.navset_pill
- express.ui.navset_pill_list
- express.ui.navset_tab
- express.ui.navset_underline
- express.ui.value_box
- express.ui.panel_well
- express.ui.panel_conditional
- express.ui.panel_fixed
- express.ui.panel_absolute
- express.ui.page_fluid
- express.ui.page_fixed
- express.ui.page_fillable
- express.ui.page_sidebar
- express.ui.page_navbar
- title: Deprecated
desc: ""
contents:
Expand Down
10 changes: 5 additions & 5 deletions examples/express/accordion_app.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import matplotlib.pyplot as plt
import numpy as np

from shiny import render, ui
from shiny.express import input, layout
from shiny import render
from shiny.express import input, ui

with layout.accordion(open=["Panel 1", "Panel 2"]):
with layout.accordion_panel("Panel 1"):
with ui.accordion(open=["Panel 1", "Panel 2"]):
with ui.accordion_panel("Panel 1"):
ui.input_slider("n", "N", 1, 100, 50)

with layout.accordion_panel("Panel 2"):
with ui.accordion_panel("Panel 2"):

@render.text
def txt():
Expand Down
4 changes: 2 additions & 2 deletions examples/express/basic_app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from shiny import render, ui
from shiny.express import input
from shiny import render
from shiny.express import input, ui

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

Expand Down
12 changes: 6 additions & 6 deletions examples/express/column_wrap_app.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import matplotlib.pyplot as plt
import numpy as np

from shiny import render, ui
from shiny.express import input, layout
from shiny import render
from shiny.express import input, ui

with layout.layout_column_wrap(width=1 / 2):
with layout.card():
with ui.layout_column_wrap(width=1 / 2):
with ui.card():
ui.input_slider("n", "N", 1, 100, 50)

with layout.card():
with ui.card():

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

with layout.card():
with ui.card():

@render.plot
def histogram2():
Expand Down
18 changes: 9 additions & 9 deletions examples/express/nav_app.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import matplotlib.pyplot as plt
import numpy as np

from shiny import render, ui
from shiny.express import input, layout
from shiny import render
from shiny.express import input, ui

with layout.layout_column_wrap(width=1 / 2):
with layout.navset():
with layout.nav_panel(title="One"):
with ui.layout_column_wrap(width=1 / 2):
with ui.navset_underline():
with ui.nav_panel(title="One"):
ui.input_slider("n", "N", 1, 100, 50)

with layout.nav_panel(title="Two"):
with ui.nav_panel(title="Two"):

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

with layout.navset_card():
with layout.nav_panel(title="One"):
with ui.navset_card_underline():
with ui.nav_panel(title="One"):
ui.input_slider("n2", "N", 1, 100, 50)

with layout.nav_panel(title="Two"):
with ui.nav_panel(title="Two"):

@render.plot
def histogram2():
Expand Down
4 changes: 2 additions & 2 deletions examples/express/shared_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import numpy as np
import shared

from shiny import reactive, render, ui
from shiny.express import input
from shiny import reactive, render
from shiny.express import input, ui


@render.plot
Expand Down
6 changes: 3 additions & 3 deletions examples/express/sidebar_app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import matplotlib.pyplot as plt
import numpy as np

from shiny import render, ui
from shiny.express import input, layout
from shiny import render
from shiny.express import input, ui

with layout.sidebar():
with ui.sidebar():
ui.input_slider("n", "N", 1, 100, 50)


Expand Down
4 changes: 2 additions & 2 deletions shiny/express/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from ..session import Inputs, Outputs, Session
from ..session import _utils as _session_utils
from . import app, layout
from . import app, ui
from ._is_express import is_express_app
from ._output import output_args, suspend_display
from ._run import wrap_express_app
Expand All @@ -17,7 +17,7 @@
"suspend_display",
"wrap_express_app",
"app",
"layout",
"ui",
"display_body",
)

Expand Down
15 changes: 14 additions & 1 deletion shiny/express/_recall_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from types import TracebackType
from typing import Callable, Generic, Mapping, Optional, Type, TypeVar

from htmltools import Tag, wrap_displayhook_handler
from htmltools import MetadataNode, Tag, TagList, wrap_displayhook_handler

from .._typing_extensions import ParamSpec

Expand Down Expand Up @@ -54,6 +54,19 @@ def __exit__(
sys.displayhook(res)
return False

def tagify(self) -> Tag | TagList | MetadataNode | str:
res = self.fn(*self.args, **self.kwargs)

if callable(getattr(res, "tagify", None)):
return res.tagify() # pyright: ignore
if callable(getattr(res, "_repr_html_", None)):
return res._repr_html_() # pyright: ignore

raise RuntimeError(
"RecallContextManager was used without `with`. When used this way, the "
"result must have a .tagify() or ._repr_html_() method, but it does not."
)


def wrap_recall_context_manager(
fn: Callable[P, R]
Expand Down
Loading

0 comments on commit b6451fd

Please sign in to comment.