Skip to content

Commit

Permalink
docs(examples): Use refactored shinylive syntax (#1048)
Browse files Browse the repository at this point in the history
  • Loading branch information
gadenbuie authored Jan 24, 2024
1 parent 39bcfdd commit 054f493
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ doc =
jupyter
jupyter_client < 8.0.0
tabulate
shinylive @ git+https://github.com/posit-dev/py-shinylive.git@main
shinylive @ git+https://github.com/posit-dev/py-shinylive.git
pydantic==1.10
quartodoc==0.7.2
griffe==0.33.0
Expand Down
24 changes: 7 additions & 17 deletions shiny/_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,29 +177,19 @@ def _(func: F) -> F:
# This part is hidden from the typechecker because shinylive is not a direct
# dependency of shiny and we only need this section when building the docs.
try:
import shinylive
from shinylive import ShinyliveApp
except ImportError:
raise RuntimeError(
"Please install the latest version of shinylive to build the docs."
)
except ModuleNotFoundError:
raise RuntimeError("Please install shinylive to build the docs.")

SHINYLIVE_CODE_TEMPLATE = """
```{{shinylive-python}}
#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400
{0}
```
"""

class ShinyliveExampleWriter(ExampleWriter):
def write_example(self, app_files: list[str]) -> str:
app_file = app_files.pop(0)
bundle = shinylive._url.create_shinylive_bundle_file(
app_file, app_files, language="py"
)
code = shinylive._url.create_shinylive_chunk_contents(bundle)
app = ShinyliveApp.from_local(app_file, app_files, language="py")

return SHINYLIVE_CODE_TEMPLATE.format(code.strip())
return app.to_chunk(layout="vertical", viewer_height=400)

example_writer = ShinyliveExampleWriter()

0 comments on commit 054f493

Please sign in to comment.