From af63f3b2c7a2024f3adc1300292ebcf64deb86e9 Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Wed, 3 Jul 2024 10:19:20 -0400 Subject: [PATCH 1/3] docs(Theme): Fix example and clarify usage --- shiny/ui/_theme.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/shiny/ui/_theme.py b/shiny/ui/_theme.py index eb5fe14a0..62012b31b 100644 --- a/shiny/ui/_theme.py +++ b/shiny/ui/_theme.py @@ -63,11 +63,11 @@ class Theme: caches the compiled CSS so that it's only compiled for the first user to load your app, but you can speed up app loading (and avoid the runtime `libsass` dependency) by pre-compiling the theme CSS and saving it to a file. To do this, use the - `.to_css()` method to render the theme to a single minified CSS string. Once saved - to a file, the CSS can be used in any Shiny app by passing the file path to the - `theme` argument instead of the `Theme` object. + `.to_css()` method to render the theme to a single minified CSS string. ```{.python filename="my_theme.py"} + from pathlib import Path + from shiny import ui my_theme = ( @@ -79,17 +79,23 @@ class Theme: ) ) - with open("my_theme.css", "w") as f: + with open(Path(__file__).parent / "my_theme.css", "w") as f: f.write(my_theme.to_css()) ``` + Run this script with `python my_theme.py` to generate the CSS file. Once saved to a + file, the CSS can be used in any Shiny app by passing the file path to the `theme` + argument instead of the `Theme` object. + ```{.python filename="app.py"} + from pathlib import Path + from shiny import ui ui = ui.page_fluid( # App content here title="My App", - theme="my_theme.css", + theme=Path(__file__).parent / "my_theme.css", ) ``` From 4e7ff71172d3038733fc0835536ab0e0a846617e Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Wed, 3 Jul 2024 10:34:47 -0400 Subject: [PATCH 2/3] chore: Make app runnable --- shiny/ui/_theme.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/shiny/ui/_theme.py b/shiny/ui/_theme.py index 62012b31b..3ecb930ea 100644 --- a/shiny/ui/_theme.py +++ b/shiny/ui/_theme.py @@ -90,13 +90,18 @@ class Theme: ```{.python filename="app.py"} from pathlib import Path - from shiny import ui + from shiny import App, ui - ui = ui.page_fluid( + app_ui = ui.page_fluid( # App content here title="My App", theme=Path(__file__).parent / "my_theme.css", ) + + def server(input): + pass + + app = App(app_ui, server) ``` Parameters From 7fc6638a96d0d501a02f4aca5a06096770a785e3 Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Wed, 3 Jul 2024 10:37:59 -0400 Subject: [PATCH 3/3] docs: Make example more runnable --- shiny/ui/_theme.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/shiny/ui/_theme.py b/shiny/ui/_theme.py index 3ecb930ea..f86275c76 100644 --- a/shiny/ui/_theme.py +++ b/shiny/ui/_theme.py @@ -72,10 +72,11 @@ class Theme: my_theme = ( ui.Theme("shiny") + .add_defaults( + my_purple="#aa00aa", + ) .add_mixins( - headings_color="$success", - bar_color="$purple", - select_color_text="$orange", + headings_color="$my-purple", ) ) @@ -93,6 +94,7 @@ class Theme: from shiny import App, ui app_ui = ui.page_fluid( + ui.h2("Hello, themed Shiny!"), # App content here title="My App", theme=Path(__file__).parent / "my_theme.css",