Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(examples): Use refactored shinylive syntax #1048

Merged
merged 6 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we release py-shinylive before shiny, we'd want to set this line to the newly released version before releasing shiny.

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()