Skip to content

Commit

Permalink
Update shinylive helpers to better support R (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert committed Jun 18, 2024
1 parent c6cba08 commit c1f595d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions docs/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ def shinylive_chunk(
components: Sequence[str] = ("editor", "viewer"),
viewer_height: str = "400",
layout: Literal["horizontal", "vertical"] = "horizontal",
language: Literal["py", "r"] = "py",
):
lang = "python" if language == "py" else "r"
block = QuartoPrint(
[
"```{shinylive-python}",
f"```{{shinylive-{lang}}}",
"#| standalone: true",
f"#| components: [{', '.join(components)}]",
f"#| layout: {layout}",
Expand Down Expand Up @@ -80,9 +82,10 @@ def _include_shiny_folder(
folder_path = Path(__name__).parent / path

# Start with the header
lang = "python" if file_name.endswith(".py") else "r"
block = QuartoPrint(
[
"```{shinylive-python}",
f"```{{shinylive-{lang}}}",
"#| standalone: true",
f"#| components: [{', '.join(components)}]",
"#| layout: horizontal",
Expand Down Expand Up @@ -230,10 +233,11 @@ def express_core_preview(
continue

sl_app = ShinyliveApp.from_local(app_file, files, language)
lang = "python" if language == "py" else "r"

block.append("### " + tab_name)
block.append(
'```{.python .code-overflow-scroll shinylive="' + sl_app.to_url() + '"}'
f'```{{.{lang} .code-overflow-scroll shinylive="{sl_app.to_url()}"}}'
)
block.append_file(app_file)
block.extend(["```", ""])
Expand Down

0 comments on commit c1f595d

Please sign in to comment.