Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow page_sidebar and page_navbar to take sidebars as unnamed args #942

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

wch
Copy link
Collaborator

@wch wch commented Dec 23, 2023

This closes #939.

I didn't do this for the navset_ functions (like navset_card_tab) but I think they probably should have similar modifications.

@wch wch added this to the v0.7.0 milestone Dec 23, 2023
@wch wch requested a review from schloerke January 3, 2024 02:17
*args
UI elements.
UI elements. One of the elements must be a sidebar.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
UI elements. One of the elements must be a sidebar.
UI elements. One of the elements must be a :class:`shiny.ui.Sidebar`.

Comment on lines +90 to +94
"page_sidebar() requires one sidebar, but no sidebars were found in args. Use `ui.sidebar(...)` to create one."
)
elif len(sidebars) > 1:
raise ValueError(
"page_sidebar() requires exactly one sidebar, but more sidebars were found in args."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"page_sidebar() requires one sidebar, but no sidebars were found in args. Use `ui.sidebar(...)` to create one."
)
elif len(sidebars) > 1:
raise ValueError(
"page_sidebar() requires exactly one sidebar, but more sidebars were found in args."
"`page_sidebar()` requires one `Sidebar`, but no sidebars were found in `*args`. Use `ui.sidebar(...)` to create one."
)
elif len(sidebars) > 1:
raise ValueError(
"`page_sidebar()` requires exactly one `Sidebar`, but more sidebars were found in `*args`."

"page_sidebar() requires exactly one sidebar, but more sidebars were found in args."
)
sidebar = sidebars[0]
args = tuple([x for x in args if x not in sidebars])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove here. Update above.

Suggested change
args = tuple([x for x in args if x not in sidebars])

@@ -85,6 +83,19 @@ def page_sidebar(
if isinstance(title, str):
title = tags.h1(title, class_="bslib-page-title")

# Extract sidebar from args
sidebars = [x for x in args if isinstance(x, Sidebar)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make both tuples right away (without having to convert from list)

Suggested change
sidebars = [x for x in args if isinstance(x, Sidebar)]
sidebars = (x for x in args if isinstance(x, Sidebar))
args = (x for x in args if not isinstance(x, Sidebar))

"`sidebar=` is not a `Sidebar` instance. Use `ui.sidebar(...)` to create one."
if sidebar is None:
# Extract sidebar from args
sidebars = [x for x in args if isinstance(x, Sidebar)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use tuple...

Suggested change
sidebars = [x for x in args if isinstance(x, Sidebar)]
sidebars = (x for x in args if isinstance(x, Sidebar))

sidebars = [x for x in args if isinstance(x, Sidebar)]
if len(sidebars) == 1:
sidebar = sidebars[0]
args = tuple([x for x in args if x not in sidebars])
Copy link
Collaborator

@schloerke schloerke Jan 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
args = tuple([x for x in args if x not in sidebars])
args = (x for x in args if not isinstance(x, Sidebar))

@wch wch removed this from the v0.7.0 milestone Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

page_sidebar and page_navbar should drop sidebar parameter and accept Sidebar objects in *args
2 participants