diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d8ef038..d08a3f7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 2.8.2 + +- Add support to run r applications with plumber and shiny + ## 2.8.1 - Automatically create `.storage` folder when it does not exist diff --git a/python/hal9/run.py b/python/hal9/run.py index fd693795..c7a9b0a9 100644 --- a/python/hal9/run.py +++ b/python/hal9/run.py @@ -3,6 +3,8 @@ from hal9.runtimes.image import run as run_image from hal9.runtimes.python import run as run_python from hal9.runtimes.chainlit import run as run_chainlit +from hal9.runtimes.r import run as run_r +from hal9.runtimes.plumber import run as run_plumber runtime_types = { "python": run_python, @@ -10,6 +12,9 @@ "jpg": run_image, "png": run_image, "chainlit": run_chainlit, + "r": run_r, + "shiny": run_r, + "plumber": run_plumber, } def run(path :str, source :str = "app.py", runtime :str = "python", port :str = "8080") -> str: diff --git a/python/hal9/runtimes/plumber.py b/python/hal9/runtimes/plumber.py new file mode 100644 index 00000000..ca9cbf01 --- /dev/null +++ b/python/hal9/runtimes/plumber.py @@ -0,0 +1,8 @@ +import subprocess +from pathlib import Path + +def run(source_path :Path, port :str): + code = f"library(plumber);pr_run(pr('{source_path}'), port={port})" + command = ['Rscript', '-e', code] + with subprocess.Popen(command) as proc: + proc.wait() diff --git a/python/hal9/runtimes/r.py b/python/hal9/runtimes/r.py new file mode 100644 index 00000000..b84e14e7 --- /dev/null +++ b/python/hal9/runtimes/r.py @@ -0,0 +1,15 @@ +import subprocess +from pathlib import Path + +def run(source_path :Path, port :str): + rprofile_content = f""" +options(shiny.port = {port}) +""" + + rprofile_path = Path.cwd() / ".Rprofile" + with open(rprofile_path, "w") as rprofile_file: + rprofile_file.write(rprofile_content) + + command = ['Rscript', source_path] + with subprocess.Popen(command) as proc: + proc.wait() diff --git a/python/pyproject.toml b/python/pyproject.toml index 716da93e..30f7dc48 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "hal9" -version = "2.8.1" +version = "2.8.2" description = "" authors = ["Javier Luraschi "] readme = "README.md"