Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1716b1d
Add TopLevelRecallContextManager which inspects args to infer page de…
cpsievert Dec 11, 2023
5fa9a52
WIP convert layout to ui
wch Dec 12, 2023
19b8f44
Add remaining components to shiny.express.ui
wch Dec 12, 2023
fac3ca2
Install htmltools from github
wch Dec 13, 2023
d9361d2
Update examples
wch Dec 13, 2023
f03bb44
Better test error messages
wch Dec 13, 2023
74412af
Update express UI components
wch Dec 13, 2023
63e7307
Merge remote-tracking branch 'origin/main' into express-layout-to-ui
wch Dec 14, 2023
9d75b26
Remove row and column from express.ui
wch Dec 14, 2023
d3e5f32
Merge branch 'main' into express-inspect-args
wch Dec 15, 2023
b552067
Move TopLevelRecallContextManager code to page_auto
wch Dec 15, 2023
1a8935d
For multiple sidebars, require use of layout_sidebar()
wch Dec 15, 2023
8afcc28
Add set_page_*, use_page_* functions
wch Dec 16, 2023
af25ce2
Update docstrings
wch Dec 18, 2023
38472f0
Merge branch 'main' into express-layout-to-ui
wch Dec 20, 2023
55b60fd
Add .tagify() method to RecallContextManager
wch Dec 20, 2023
16d03f2
Add shiny.express.layout compatibility shim
wch Dec 21, 2023
364cbad
Remove navset and navset_card
wch Dec 21, 2023
b3db4db
Fix example app
wch Dec 21, 2023
b084224
Fix exports
wch Dec 21, 2023
675d015
Update docstrings
wch Dec 21, 2023
0366460
Update test apps
wch Dec 21, 2023
8df8d94
Import fixes in test apps
wch Dec 21, 2023
2f801f7
Documentation updates
wch Dec 21, 2023
1a7cdd8
Merge branch 'express-layout-to-ui' into express-inspect-args-2
wch Dec 21, 2023
a7b6664
Update known missing items
wch Dec 21, 2023
31c8130
Update quartodoc entries
wch Dec 21, 2023
06b31e0
API updates
wch Dec 21, 2023
c03f684
Update page_auto
wch Dec 21, 2023
cdf8a3e
Replace set_page() with page_opts()
wch Dec 21, 2023
cb7886e
Merge remote-tracking branch 'origin/main' into express-inspect-args
wch Dec 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions docs/_quartodoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ quartodoc:
- ui.page_fluid
- ui.page_fixed
- ui.page_bootstrap
- ui.page_auto
- ui.page_output
- title: UI Layouts
desc: Control the layout of multiple UI components.
contents:
Expand Down Expand Up @@ -290,7 +292,6 @@ quartodoc:
desc: ""
flatten: true
contents:
- express.ui.set_page
- express.ui.sidebar
- express.ui.layout_sidebar
- express.ui.layout_column_wrap
Expand All @@ -315,11 +316,15 @@ quartodoc:
- 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
contents:
- kind: page
path: PageFunctions
summary:
name: "Page functions"
desc: ""
flatten: true
contents:
- express.ui.page_opts
- title: Deprecated
desc: ""
contents:
Expand Down
4 changes: 2 additions & 2 deletions examples/express/plot_app.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import matplotlib.pyplot as plt
import numpy as np

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
7 changes: 0 additions & 7 deletions shiny/express/_recall_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ def __init__(
self,
fn: Callable[..., R],
*,
default_page: RecallContextManager[Tag] | None = None,
args: tuple[object, ...] | None = None,
kwargs: Mapping[str, object] | None = None,
):
self.fn = fn
self.default_page = default_page
if args is None:
args = tuple()
if kwargs is None:
Expand All @@ -33,11 +31,6 @@ def __init__(
self.kwargs: dict[str, object] = dict(kwargs)

def __enter__(self) -> None:
if self.default_page is not None:
from . import _run

_run.replace_top_level_recall_context_manager(self.default_page)

self._prev_displayhook = sys.displayhook
# Collect each of the "printed" values in the args list.
sys.displayhook = wrap_displayhook_handler(self.args.append)
Expand Down
59 changes: 3 additions & 56 deletions shiny/express/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from htmltools import Tag, TagList

from .. import ui
from .._app import App
from ..session import Inputs, Outputs, Session
from ._recall_context import RecallContextManager
Expand All @@ -20,8 +19,6 @@

__all__ = ("wrap_express_app",)

_DEFAULT_PAGE_FUNCTION = ui.page_fixed


def wrap_express_app(file: Path) -> App:
"""Wrap a Shiny Express mode app into a Shiny `App` object.
Expand Down Expand Up @@ -133,64 +130,14 @@ def set_result(x: object):


_top_level_recall_context_manager: RecallContextManager[Tag]
_top_level_recall_context_manager_has_been_replaced = False


def reset_top_level_recall_context_manager() -> None:
from .ui._page import page_auto_cm

global _top_level_recall_context_manager
global _top_level_recall_context_manager_has_been_replaced
_top_level_recall_context_manager = RecallContextManager(_DEFAULT_PAGE_FUNCTION)
_top_level_recall_context_manager_has_been_replaced = False
_top_level_recall_context_manager = page_auto_cm()


def get_top_level_recall_context_manager() -> RecallContextManager[Tag]:
return _top_level_recall_context_manager


def replace_top_level_recall_context_manager(
cm: RecallContextManager[Tag],
force: bool = False,
) -> RecallContextManager[Tag]:
"""
Replace the current top level RecallContextManager with another one.

This transfers the `args` and `kwargs` from the previous RecallContextManager to the
new one. Normally it will only have an effect the first time it's run; it only
replace the previous one if has not already been replaced. To override this
behavior, this use `force=True`.

Parameters
----------
cm
The RecallContextManager to replace the previous one.
force
If `False` (the default) and the top level RecallContextManager has already been
replaced, return with no chnages. If `True`, this will aways replace.

Returns
-------
:
The previous top level RecallContextManager.
"""
global _top_level_recall_context_manager
global _top_level_recall_context_manager_has_been_replaced

old_cm = _top_level_recall_context_manager

if force is False and _top_level_recall_context_manager_has_been_replaced:
return old_cm

args = old_cm.args.copy()
args.extend(cm.args)
cm.args = args

kwargs = old_cm.kwargs.copy()
kwargs.update(cm.kwargs)
cm.kwargs = kwargs

old_cm.__exit__(BaseException, None, None)
cm.__enter__()
_top_level_recall_context_manager = cm
_top_level_recall_context_manager_has_been_replaced = True

return old_cm
26 changes: 13 additions & 13 deletions shiny/express/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
)

from ._cm_components import (
set_page,
sidebar,
layout_sidebar,
layout_column_wrap,
Expand All @@ -134,11 +133,10 @@
panel_conditional,
panel_fixed,
panel_absolute,
page_fluid,
page_fixed,
page_fillable,
page_sidebar,
page_navbar,
)

from ._page import (
page_opts,
)

__all__ = (
Expand Down Expand Up @@ -245,7 +243,6 @@
"output_data_frame",
"value_box_theme",
# Imports from ._cm_components
"set_page",
"sidebar",
"layout_sidebar",
"layout_column_wrap",
Expand All @@ -272,11 +269,8 @@
"panel_conditional",
"panel_fixed",
"panel_absolute",
"page_fluid",
"page_fixed",
"page_fillable",
"page_sidebar",
"page_navbar",
# Imports from ._page
"page_opts",
)


Expand All @@ -290,6 +284,12 @@
"navset_pill_card", # Deprecated
"navset_tab_card", # Deprecated
"page_bootstrap",
"page_fixed",
"page_sidebar",
"page_fillable",
"page_navbar",
"page_fluid",
"page_auto",
"page_output",
"panel_main", # Deprecated
"panel_sidebar", # Deprecated
Expand All @@ -301,5 +301,5 @@
"tooltip",
),
# Items from shiny.express.ui that don't have a counterpart in shiny.ui
"shiny.express.ui": ("set_page",),
"shiny.express.ui": ("page_opts",),
}
Loading