Skip to content

Commit

Permalink
Improved parsing of query params.
Browse files Browse the repository at this point in the history
  • Loading branch information
filipstachura committed Nov 8, 2024
2 parents 8f31a7f + 0030680 commit fc6ac60
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
.pyc
__pycache__/
*.egg-info
build
dist
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include inst *
14 changes: 12 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
[project]
name = "shiny-router"
version = "0.1.0"
name = "shiny_router"
version = "0.1.3"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"pandas",
"shiny",
"shiny-router",
]

[tool.setuptools]
include-package-data = true

[tool.setuptools.package-data]
"shiny_router" = ["www/*"]

[tool.uv.sources]
shiny-router = { workspace = true }
2 changes: 1 addition & 1 deletion src/shiny_router/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .router import route_link, router_ui, route, router_server

def hello() -> str:
return "Hello from shiny-router!"
return "Hello from shiny_router!"
18 changes: 13 additions & 5 deletions src/shiny_router/router.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from shiny import ui, reactive
from htmltools import HTMLDependency
from pathlib import PurePath
from urllib.parse import urlparse, parse_qs

log_msg = print
PAGE_404_ROUTE = "404"
Expand Down Expand Up @@ -36,15 +37,22 @@ def router_callback(input, output, session=None, **kwargs):
query = None,
unparsed = root
))

@reactive.effect
@reactive.event(input._clientdata_url_hash)
def _():
requested_path = input._clientdata_url_hash()
clean_path = requested_path[3:] if requested_path.startswith("#!/") else requested_path
# TODO: Below simplifies and is incorrect:
parsed_url = urlparse(requested_path)
fragment_path = urlparse(parsed_url.fragment)
clean_path = fragment_path.path.lstrip("!").lstrip("/")
query_params = parse_qs(fragment_path.query)

print("Path:", clean_path)
print("Query Parameters:", query_params)

input.shiny_router_page.set(dict(
path = clean_path if clean_path else root,
query = None,
path = clean_path,
query = query_params,
unparsed = requested_path,
))

Expand Down Expand Up @@ -109,7 +117,7 @@ def router_ui_internal(router):
pkg_dependency = HTMLDependency("shiny_router", "0.0.1",
source={
"package": "shiny_router",
"subdir": str(PurePath(__file__).parent.parent.parent / "inst" / "www"),
"subdir": str(PurePath(__file__).parent / "www"),
},
script={"src": js_file, "type": "module"},
stylesheet={"href": css_file}
Expand Down
1 change: 1 addition & 0 deletions src/shiny_router/www
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 fc6ac60

Please sign in to comment.