From bab72a17d0580ef1048f8a11f143c765fe581c68 Mon Sep 17 00:00:00 2001 From: Dawa Ometto Date: Wed, 19 Nov 2025 12:23:26 +0100 Subject: [PATCH 1/4] Allow specifying server prefix and R path --- jupyter_rsession_proxy/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/jupyter_rsession_proxy/__init__.py b/jupyter_rsession_proxy/__init__.py index 59e85be..a061ad3 100644 --- a/jupyter_rsession_proxy/__init__.py +++ b/jupyter_rsession_proxy/__init__.py @@ -54,7 +54,7 @@ def get_system_user(): user = os.getenv('NB_USER', getpass.getuser()) return(user) -def setup_rserver(): +def setup_rserver(r_path="", prefix="rstudio"): def _get_env(port, unix_socket): return dict(USER=get_system_user()) @@ -112,13 +112,16 @@ def _get_cmd(port, unix_socket): 'database-config-file', 'www-thread-pool-size', 'www-socket', + 'rsession-which-r' ]) if supported_args['www-root-path']: - cmd.append('--www-root-path={base_url}rstudio/') + cmd.append('--www-root-path={base_url}' + f'{prefix}/') if supported_args['server-data-dir']: cmd.append(f'--server-data-dir={server_data_dir}') if supported_args['database-config-file']: cmd.append(f'--database-config-file={database_config_file}') + if supported_args['rsession-which-r'] and r_path: + cmd.append(f'--rsession-which-r={r_path}') if supported_args['www-thread-pool-size']: thread_pool_size_env = os.getenv('JUPYTER_RSESSION_PROXY_THREAD_POOL_SIZE', None) From a2fc2ca09ab5449239f888dcc368ad0c1ccb1029 Mon Sep 17 00:00:00 2001 From: Dawa Ometto Date: Wed, 19 Nov 2025 12:55:53 +0100 Subject: [PATCH 2/4] Also make launcher entry title configurable --- jupyter_rsession_proxy/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jupyter_rsession_proxy/__init__.py b/jupyter_rsession_proxy/__init__.py index a061ad3..b4270fa 100644 --- a/jupyter_rsession_proxy/__init__.py +++ b/jupyter_rsession_proxy/__init__.py @@ -54,7 +54,7 @@ def get_system_user(): user = os.getenv('NB_USER', getpass.getuser()) return(user) -def setup_rserver(r_path="", prefix="rstudio"): +def setup_rserver(r_path="", prefix="rstudio", launcher_title="RStudio"): def _get_env(port, unix_socket): return dict(USER=get_system_user()) @@ -153,7 +153,7 @@ def _get_timeout(default=15): 'environment': _get_env, 'rewrite_response': rewrite_netloc, 'launcher_entry': { - 'title': 'RStudio', + 'title': launcher_title, 'icon_path': get_icon_path() } } From 51afbfbe8460441719f416508c106420cb37cfc7 Mon Sep 17 00:00:00 2001 From: Dawa Ometto Date: Mon, 24 Nov 2025 14:08:54 +0100 Subject: [PATCH 3/4] Add documentation on traitlets config for multiple servers --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 5eb7384..30a2f3b 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,25 @@ Or via `conda`: conda install -c conda-forge jupyter-rsession-proxy ``` +### Traitlets configuration + +You may also manually configure this extension inside a [traitlets](https://traitlets.readthedocs.io/en/stable/) configuration file for [jupyter-server-proxy](https://jupyter-server-proxy.readthedocs.io/en/latest/server-process.html#specifying-config-via-traitlets). This also allows you to configure multiple different RStudio applications, for instance using different versions of R: + +```python +from jupyter_rsession_proxy import setup_rserver +# update the jupyter-server-proxy config by adding two RStudio servers +c.ServerProxy.servers.update({ + "rstudio1": setup_rserver(prefix="rstudio1", r_path="/usr/bin/R", launcher_title="RStudio (default R)"), + "rstudio2": setup_rserver(prefix="rstudio2", r_path="/opt/miniconda3/bin/R", launcher_title="RStudio (other R)") +}) +# note that the prefix and the dict key are the same for each server (both "rstudio1" and "rstudio2", respectively). +# this is necessary for everything to work correctly: +# if prefix and dict key differ, then the user would not be redirected to the right URL. +``` + +Note: in this scenario, `jupyter-rsession-proxy` must still first be installed (into the same environment as Jupyter) as described [above](#install-jupyter-rsession-proxy). + + ## Example [rocker/binder](https://hub.docker.com/r/rocker/binder) contains an example installation which you can run on binder. From 045d48da4ce2c365693a01396e6e061a54219be3 Mon Sep 17 00:00:00 2001 From: Dawa Ometto Date: Mon, 15 Dec 2025 15:27:38 +0100 Subject: [PATCH 4/4] Ensure base_url and prefix are separated by a slash --- jupyter_rsession_proxy/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyter_rsession_proxy/__init__.py b/jupyter_rsession_proxy/__init__.py index b4270fa..2be99cc 100644 --- a/jupyter_rsession_proxy/__init__.py +++ b/jupyter_rsession_proxy/__init__.py @@ -115,7 +115,7 @@ def _get_cmd(port, unix_socket): 'rsession-which-r' ]) if supported_args['www-root-path']: - cmd.append('--www-root-path={base_url}' + f'{prefix}/') + cmd.append('--www-root-path={base_url}' + f'/{prefix}/') if supported_args['server-data-dir']: cmd.append(f'--server-data-dir={server_data_dir}') if supported_args['database-config-file']: