From cf2589c664a1a0c15ade956943d93cf2d100f2dd Mon Sep 17 00:00:00 2001 From: Carson Date: Tue, 18 Jun 2024 17:07:58 -0500 Subject: [PATCH] Follow up to #159: auto-detect language in append_shinylive_chunk() --- docs/helpers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/helpers.py b/docs/helpers.py index 57d45c79..9b5fee6f 100644 --- a/docs/helpers.py +++ b/docs/helpers.py @@ -23,7 +23,7 @@ def append_file(self, file_path: str, file_name: Optional[str] = None): def append_shinylive_chunk( self, files: list[str] | str, - language: str = "py", + language: Literal["auto", "py", "r"] = "auto", **kwargs, ): if isinstance(files, str): @@ -32,6 +32,9 @@ def append_shinylive_chunk( else: app_file = files.pop(0) + if language == "auto": + language = "py" if app_file.endswith(".py") else "r" + app = ShinyliveApp.from_local(app_file, files, language) self.append(app.to_chunk(**kwargs))