posit-dev / py-shinyswatch

Bootswatch themes for py-shiny
https://posit-dev.github.io/py-shinyswatch/
MIT License
28 stars 3 forks source link

Switch shinyswatch.theme.<theme_name> -> shinyswatch.theme.<theme_name>() for py-shinylive #31

Closed coatless closed 8 months ago

coatless commented 8 months ago

If we take the demo app listed in the README and place it into a py-shinylive app, then we get an error

TypeError: Invalid tag item type: . Consider calling str() on this value before treating it as a tag item ``` Traceback (most recent call last): File "", line 381, in _start_app File "/lib/python3.10/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1053, in _gcd_import File "", line 1030, in _find_and_load File "", line 1009, in _find_and_load_unlocked File "", line 688, in _load_unlocked File "", line 883, in exec_module File "", line 241, in _call_with_frames_removed File "/home/pyodide/app_xfw4jdffnf9ri4l3857k/app.py", line 5, in app_ui = ui.page_fluid( File "/lib/python3.10/site-packages/shiny/ui/_page.py", line 386, in page_fluid div({"class": "container-fluid"}, *args, **kwargs), title=title, lang=lang File "/lib/python3.10/site-packages/htmltools/tags.py", line 731, in div return Tag("div", *args, _add_ws=_add_ws, **kwargs) File "/lib/python3.10/site-packages/htmltools/_core.py", line 564, in __init__ self.children = TagList(*kids) File "/lib/python3.10/site-packages/htmltools/_core.py", line 186, in __init__ super().__init__(_tagchilds_to_tagnodes(args)) File "/lib/python3.10/site-packages/htmltools/_core.py", line 1723, in _tagchilds_to_tagnodes raise TypeError( TypeError: Invalid tag item type: . Consider calling str() on this value before treating it as a tag item. ```
Example of a shinyswatch theme not working in shinylive by treating the theme as an object instead of a function

If we change the theme line to use parentheses instead of being treated as an object, then the shinylive app works

Example of a shinyswatch theme working in shinylive by treating the theme as a function instead of object
gadenbuie commented 8 months ago

Thanks @coatless! It looks like shinyswatch is out of date in shinylive, the syntax in the README requires shinyswatch 0.5.0.

>>> shinyswatch.__version__
'0.4.1'

The example you provided runs correctly for me locally with Shiny Express and the latest shinyswatch.

wch commented 8 months ago

I pushed a fix in https://github.com/posit-dev/shinylive/commit/93f4c1ac1ca2ba45df454a8df07371abd90a11da, which should be deployed shortly.