-
Notifications
You must be signed in to change notification settings - Fork 117
feat: Add theme argument to page functions
#1334
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c03c71d
feat(ui.page_*): Add `theme` argument to page functions
gadenbuie 700856c
tests: Add a example apps
gadenbuie bd2af17
feat: Add `ThemeProvider` type
gadenbuie 29ca904
chore: fix type issues in deprecated functions
gadenbuie 251f6a1
feat(express.ui.page_opts): Add `theme` parameter
gadenbuie e9f1d39
fix: handle `theme=None` case
gadenbuie db04606
chore: fix typing for older versions of python
gadenbuie 03a4309
chore: don't splat `bootstrap_theme_deps()`
gadenbuie 19638c5
feat: remote theme URLs could start with double slash
gadenbuie 51295a9
fix: use quotes for `list["HTMLDependency"]`
gadenbuie 6d899d2
chore: Add note about purgecss requirement
gadenbuie 71d96c1
refactor: Use `List[]` syntax
gadenbuie fde759e
docs: Add changelog item
gadenbuie 35b0576
Merge branch 'main' into feat/theme-css-path
gadenbuie fc3c6db
fix: name of css file in test/example app
gadenbuie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # This file is used to create a minimal Bootstrap CSS file based on the Minty | ||
| # Bootstwatch theme for use in the example apps. | ||
|
|
||
| # NOTE: This script requires the `purgecss` package to be installed. | ||
| # You can install it with `npm install -g purgecss`. | ||
|
|
||
| import shutil | ||
| import subprocess | ||
| from pathlib import Path | ||
|
|
||
| import shinyswatch | ||
|
|
||
| from shiny import ui | ||
|
|
||
| app_ui = ui.page_sidebar( | ||
| ui.sidebar( | ||
| ui.input_numeric("n", "N", min=0, max=100, value=20), | ||
| title="Parameters", | ||
| ), | ||
| ui.h2("Output"), | ||
| ui.output_text_verbatim("txt"), | ||
| ui.markdown( | ||
| """ | ||
| **AI-generated filler text.** In the world of exotic fruits, the durian stands out with its spiky exterior and strong odor. Despite its divisive smell, many people are drawn to its rich, creamy texture and unique flavor profile. This tropical fruit is often referred to as the "king of fruits" in various Southeast Asian countries. | ||
|
|
||
| Durians are known for their large size and thorn-covered husk, which requires careful handling. The flesh inside can vary in color from pale yellow to deep orange, with a custard-like consistency that melts in your mouth. Some describe its taste as a mix of sweet, savory, and creamy, while others find it overpowering and pungent. | ||
| """ | ||
| ), | ||
| shinyswatch.theme.minty, | ||
| title="Theme Example", | ||
| ) | ||
|
|
||
| # If __file__ is not defined, use the current working directory | ||
| if not globals().get("__file__"): | ||
| __file__ = Path.cwd() / "_purgecss.py" | ||
|
|
||
| save_dir = Path(__file__).parent / "output" | ||
| if save_dir.exists(): | ||
| shutil.rmtree(save_dir) | ||
| save_dir.mkdir() | ||
| app_ui.save_html(save_dir / "index.html", include_version=False) | ||
|
|
||
| purged_dir = Path(__file__).parent / "css" | ||
| if purged_dir.exists(): | ||
| shutil.rmtree(purged_dir) | ||
| purged_dir.mkdir(exist_ok=True) | ||
|
|
||
| args = [ | ||
| "purgecss", | ||
| "--css", | ||
| "output/lib/shinyswatch-css/bootswatch.min.css", | ||
| "--content", | ||
| "output/index.html", | ||
| "--output", | ||
| "css", | ||
| ] | ||
|
|
||
| subprocess.run(args) | ||
|
|
||
| (purged_dir / "bootswatch.min.css").rename(purged_dir / "bootswatch-minty.min.css") | ||
|
|
||
| if True: | ||
| shutil.rmtree(save_dir) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| from shiny import App, render, ui | ||
|
|
||
| app_ui = ui.page_sidebar( | ||
| ui.sidebar( | ||
| ui.input_numeric("n", "N", min=0, max=100, value=20), | ||
| title="Parameters", | ||
| ), | ||
| ui.h2("Output"), | ||
| ui.output_text_verbatim("txt"), | ||
| ui.markdown( | ||
| """ | ||
| **AI-generated filler text.** In the world of exotic fruits, the durian stands out with its spiky exterior and strong odor. Despite its divisive smell, many people are drawn to its rich, creamy texture and unique flavor profile. This tropical fruit is often referred to as the "king of fruits" in various Southeast Asian countries. | ||
|
|
||
| Durians are known for their large size and thorn-covered husk, which requires careful handling. The flesh inside can vary in color from pale yellow to deep orange, with a custard-like consistency that melts in your mouth. Some describe its taste as a mix of sweet, savory, and creamy, while others find it overpowering and pungent. | ||
| """ | ||
| ), | ||
| title="Theme Example", | ||
| theme="https://cdn.jsdelivr.net/npm/[email protected]/dist/sketchy/bootstrap.min.css", | ||
| ) | ||
|
|
||
|
|
||
| def server(input, output, session): | ||
| @render.text | ||
| def txt(): | ||
| return f"n*2 is {input.n() * 2}" | ||
|
|
||
|
|
||
| app = App(app_ui, server) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import shinyswatch | ||
|
|
||
| from shiny import App, render, ui | ||
|
|
||
| app_ui = ui.page_sidebar( | ||
| ui.sidebar( | ||
| ui.input_numeric("n", "N", min=0, max=100, value=20), | ||
| title="Parameters", | ||
| ), | ||
| ui.h2("Output"), | ||
| ui.output_text_verbatim("txt"), | ||
| ui.markdown( | ||
| """ | ||
| **AI-generated filler text.** In the world of exotic fruits, the durian stands out with its spiky exterior and strong odor. Despite its divisive smell, many people are drawn to its rich, creamy texture and unique flavor profile. This tropical fruit is often referred to as the "king of fruits" in various Southeast Asian countries. | ||
|
|
||
| Durians are known for their large size and thorn-covered husk, which requires careful handling. The flesh inside can vary in color from pale yellow to deep orange, with a custard-like consistency that melts in your mouth. Some describe its taste as a mix of sweet, savory, and creamy, while others find it overpowering and pungent. | ||
| """ | ||
| ), | ||
| title="Theme Example", | ||
| theme=shinyswatch.theme.slate(), | ||
| ) | ||
|
|
||
|
|
||
| def server(input, output, session): | ||
| @render.text | ||
| def txt(): | ||
| return f"n*2 is {input.n() * 2}" | ||
|
|
||
|
|
||
| app = App(app_ui, server) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| from pathlib import Path | ||
|
|
||
| from shiny import App, render, ui | ||
|
|
||
| app_ui = ui.page_sidebar( | ||
| ui.sidebar( | ||
| ui.input_numeric("n", "N", min=0, max=100, value=20), | ||
| title="Parameters", | ||
| ), | ||
| ui.h2("Output"), | ||
| ui.output_text_verbatim("txt"), | ||
| ui.markdown( | ||
| """ | ||
| **AI-generated filler text.** In the world of exotic fruits, the durian stands out with its spiky exterior and strong odor. Despite its divisive smell, many people are drawn to its rich, creamy texture and unique flavor profile. This tropical fruit is often referred to as the "king of fruits" in various Southeast Asian countries. | ||
|
|
||
| Durians are known for their large size and thorn-covered husk, which requires careful handling. The flesh inside can vary in color from pale yellow to deep orange, with a custard-like consistency that melts in your mouth. Some describe its taste as a mix of sweet, savory, and creamy, while others find it overpowering and pungent. | ||
| """ | ||
| ), | ||
| title="Theme Example", | ||
| # theme=shinyswatch.theme.slate, | ||
| # theme="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css", | ||
| theme=Path(__file__).parent / "css" / "bootswatch-minty.min.css", | ||
| ) | ||
|
|
||
|
|
||
| def server(input, output, session): | ||
| @render.text | ||
| def txt(): | ||
| return f"n*2 is {input.n() * 2}" | ||
|
|
||
|
|
||
| app = App(app_ui, server) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| from shiny.express import input, render, ui | ||
|
|
||
| ui.page_opts( | ||
| title="Theme Example", | ||
| theme="https://cdn.jsdelivr.net/npm/[email protected]/dist/sketchy/bootstrap.min.css", | ||
| ) | ||
|
|
||
| with ui.sidebar(title="Parameters"): | ||
| ui.input_numeric("n", "N", min=0, max=100, value=20) | ||
|
|
||
| ui.h2("Output") | ||
|
|
||
|
|
||
| @render.code | ||
| def txt(): | ||
| return f"n*2 is {input.n() * 2}" | ||
|
|
||
|
|
||
| ui.markdown( | ||
| """ | ||
| **AI-generated filler text.** In the world of exotic fruits, the durian stands out with its spiky exterior and strong odor. Despite its divisive smell, many people are drawn to its rich, creamy texture and unique flavor profile. This tropical fruit is often referred to as the "king of fruits" in various Southeast Asian countries. | ||
|
|
||
| Durians are known for their large size and thorn-covered husk, which requires careful handling. The flesh inside can vary in color from pale yellow to deep orange, with a custard-like consistency that melts in your mouth. Some describe its taste as a mix of sweet, savory, and creamy, while others find it overpowering and pungent. | ||
| """ | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import shinyswatch | ||
|
|
||
| from shiny.express import input, render, ui | ||
|
|
||
| ui.page_opts( | ||
| title="Theme Example", | ||
| theme=shinyswatch.theme.slate, | ||
| ) | ||
|
|
||
| with ui.sidebar(title="Parameters"): | ||
| ui.input_numeric("n", "N", min=0, max=100, value=20) | ||
|
|
||
| ui.h2("Output") | ||
|
|
||
|
|
||
| @render.code | ||
| def txt(): | ||
| return f"n*2 is {input.n() * 2}" | ||
|
|
||
|
|
||
| ui.markdown( | ||
| """ | ||
| **AI-generated filler text.** In the world of exotic fruits, the durian stands out with its spiky exterior and strong odor. Despite its divisive smell, many people are drawn to its rich, creamy texture and unique flavor profile. This tropical fruit is often referred to as the "king of fruits" in various Southeast Asian countries. | ||
|
|
||
| Durians are known for their large size and thorn-covered husk, which requires careful handling. The flesh inside can vary in color from pale yellow to deep orange, with a custard-like consistency that melts in your mouth. Some describe its taste as a mix of sweet, savory, and creamy, while others find it overpowering and pungent. | ||
| """ | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| from pathlib import Path | ||
|
|
||
| from shiny.express import input, render, ui | ||
|
|
||
| ui.page_opts( | ||
| title="Theme Example", | ||
| theme=Path(__file__).parent / "css" / "bootswatch-minty.min.css", | ||
| ) | ||
|
|
||
| with ui.sidebar(title="Parameters"): | ||
| ui.input_numeric("n", "N", min=0, max=100, value=20) | ||
|
|
||
| ui.h2("Output") | ||
|
|
||
|
|
||
| @render.code | ||
| def txt(): | ||
| return f"n*2 is {input.n() * 2}" | ||
|
|
||
|
|
||
| ui.markdown( | ||
| """ | ||
| **AI-generated filler text.** In the world of exotic fruits, the durian stands out with its spiky exterior and strong odor. Despite its divisive smell, many people are drawn to its rich, creamy texture and unique flavor profile. This tropical fruit is often referred to as the "king of fruits" in various Southeast Asian countries. | ||
|
|
||
| Durians are known for their large size and thorn-covered husk, which requires careful handling. The flesh inside can vary in color from pale yellow to deep orange, with a custard-like consistency that melts in your mouth. Some describe its taste as a mix of sweet, savory, and creamy, while others find it overpowering and pungent. | ||
| """ | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
purgecssisn't installed, you'll see:FileNotFoundError: [Errno 2] No such file or directory: 'purgecss'.Probably worth a check + more informative error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't officially part of the example, just used to create it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a note at the top of the file that
purgecssis required and how to install it