Skip to content

Commit

Permalink
Fix and 0.1.5 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
filipstachura committed Nov 8, 2024
1 parent fc6ac60 commit 91101ec
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
15 changes: 13 additions & 2 deletions examples/python/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from shiny import App, ui
from shiny_router import route_link, router_ui, route, router_server
from shiny import App, ui, render, reactive
from shiny_router import route_link, router_ui, route, router_server, get_query_param

tags = ui.tags

Expand All @@ -25,6 +25,7 @@ def page(title, content):

# Make output for our router in main UI of Shiny app.
app_ui = ui.page_fluid(
ui.output_ui("param"),
router_ui(
route("/", root_page),
route("other", other_page),
Expand All @@ -36,4 +37,14 @@ def page(title, content):
def server(input, output, session):
router_server(input, output, session)

@render.ui
def param():
query = get_query_param(session = session)
id = get_query_param("id", session = session)
return ui.TagList(
ui.p("No query" if not query else str(query)),
ui.p("No id" if not id else str(id)),
)


app = App(app_ui, server)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "shiny_router"
version = "0.1.3"
version = "0.1.4"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
Expand Down
5 changes: 1 addition & 4 deletions src/shiny_router/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
from .router import route_link, router_ui, route, router_server

def hello() -> str:
return "Hello from shiny_router!"
from .router import route_link, router_ui, route, router_server, get_query_param
13 changes: 11 additions & 2 deletions src/shiny_router/router.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
from shiny import ui, reactive
from shiny import ui, reactive, session
from htmltools import HTMLDependency
from pathlib import PurePath
from urllib.parse import urlparse, parse_qs

log_msg = print
PAGE_404_ROUTE = "404"

def get_query_param(field = None, session = session.get_current_session()):
page_details = session.input.shiny_router_page()

if page_details:
if field in page_details["query"]:
return page_details["query"][field][0]
else:
return page_details["query"]

def page404(page=None, message404=None):
if page is None:
# Return a default "Not found" message or a custom 404 message
Expand Down Expand Up @@ -34,7 +43,7 @@ def router_callback(input, output, session=None, **kwargs):

input.shiny_router_page = reactive.value(dict(
path = root,
query = None,
query = {},
unparsed = root
))

Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 91101ec

Please sign in to comment.