Skip to content

Commit

Permalink
Examples for R moved to subdir. Added basic example for Python.
Browse files Browse the repository at this point in the history
  • Loading branch information
filipstachura committed Nov 7, 2024
1 parent 3c9106a commit 401b3ac
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
39 changes: 39 additions & 0 deletions examples/python/app.py
Original file line number Diff line number Diff line change
@@ -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)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 401b3ac

Please sign in to comment.