From 401b3ac812855cb54ecb9d265d8550cffd2523ba Mon Sep 17 00:00:00 2001 From: Filip Stachura Date: Thu, 7 Nov 2024 11:28:13 +0100 Subject: [PATCH] Examples for R moved to subdir. Added basic example for Python. --- README.md | 2 +- examples/python/app.py | 39 +++++++++++++++++++++++ examples/{ => r}/basic/app.R | 0 examples/{ => r}/basic_dynamic_dots/app.R | 0 examples/{ => r}/get_params.R | 0 examples/{ => r}/remember_page_state.R | 0 examples/{ => r}/shiny_modules/app.R | 0 examples/{ => r}/shiny_semantic/app.R | 0 examples/{ => r}/tutorial.R | 0 9 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 examples/python/app.py rename examples/{ => r}/basic/app.R (100%) rename examples/{ => r}/basic_dynamic_dots/app.R (100%) rename examples/{ => r}/get_params.R (100%) rename examples/{ => r}/remember_page_state.R (100%) rename examples/{ => r}/shiny_modules/app.R (100%) rename examples/{ => r}/shiny_semantic/app.R (100%) rename examples/{ => r}/tutorial.R (100%) diff --git a/README.md b/README.md index eb4abf2..20b1b7d 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ It was built using two other Appsilon Open Source packages: - [`rhino`](https://appsilon.github.io/rhino/) - an R package designed to help building high quality, enterprise-grade Shiny applications at speed. - [`shiny.fluent`](https://appsilon.github.io/shiny.fluent/) - Microsoft's Fluent UI for Shiny apps. -You can also visit [examples](https://github.com/Appsilon/shiny.router/tree/master/examples) directory for some complete samples. +You can also visit [examples](https://github.com/Appsilon/shiny.router/tree/master/examples) directory for some complete samples. This package has also experimental support for Shiny for Python, you can find examples both for R and Python. ## How to contribute? diff --git a/examples/python/app.py b/examples/python/app.py new file mode 100644 index 0000000..9d3a800 --- /dev/null +++ b/examples/python/app.py @@ -0,0 +1,39 @@ +from shiny import App, ui +from shiny_router import route_link, router_ui, route, router_server + +tags = ui.tags + +# This generates menu in user interface with links. +menu = tags.ul( + tags.li(tags.a("Page", class_ = "item", href = route_link("/"))), + tags.li(tags.a("Other page", class_ = "item", href = route_link("other"))), + tags.li(tags.a("A third page", class_ = "item", href = route_link("third"))) +) + +# This creates UI for each page. +def page(title, content): + return tags.div( + menu, + tags.h1(title), + tags.p(content), + ) + +# Both sample pages. +root_page = page("Home page", "Welcome on sample routing page!") +other_page = page("Some other page", "Lorem ipsum dolor sit amet.") +third_page = tags.div(menu, tags.h3("Third Page")) + +# Make output for our router in main UI of Shiny app. +app_ui = ui.page_fluid( + router_ui( + route("/", root_page), + route("other", other_page), + route("third", third_page) + ) +) + +# Plug router into Shiny server. +def server(input, output, session): + router_server(input, output, session) + +app = App(app_ui, server) \ No newline at end of file diff --git a/examples/basic/app.R b/examples/r/basic/app.R similarity index 100% rename from examples/basic/app.R rename to examples/r/basic/app.R diff --git a/examples/basic_dynamic_dots/app.R b/examples/r/basic_dynamic_dots/app.R similarity index 100% rename from examples/basic_dynamic_dots/app.R rename to examples/r/basic_dynamic_dots/app.R diff --git a/examples/get_params.R b/examples/r/get_params.R similarity index 100% rename from examples/get_params.R rename to examples/r/get_params.R diff --git a/examples/remember_page_state.R b/examples/r/remember_page_state.R similarity index 100% rename from examples/remember_page_state.R rename to examples/r/remember_page_state.R diff --git a/examples/shiny_modules/app.R b/examples/r/shiny_modules/app.R similarity index 100% rename from examples/shiny_modules/app.R rename to examples/r/shiny_modules/app.R diff --git a/examples/shiny_semantic/app.R b/examples/r/shiny_semantic/app.R similarity index 100% rename from examples/shiny_semantic/app.R rename to examples/r/shiny_semantic/app.R diff --git a/examples/tutorial.R b/examples/r/tutorial.R similarity index 100% rename from examples/tutorial.R rename to examples/r/tutorial.R