Closed stefanvangastel closed 4 years ago
Is it possible to add text to the topbar-extension's text bar using a (config) file?
Yes it's possible. JupyterLab settings are saved to disk in json files. It should be possible to create these files in a user environment before starting JupyterLab.
For the topbar-text extension the content can be retrieved with the following:
$ cat PREFIX/share/jupyter/lab/user-settings/jupyterlab-topbar-text/plugin.jupyterlab-settings
{
// Top Bar Text
// jupyterlab-topbar-text:plugin
// Top Bar Text
// *****************************
// Text
// Text to display
"text": "Hello"
}%
If not in PREFIX/share/jupyter
then ~/.jupyter/
might be another place to look at.
I'm using JupyterLab environments spawned by JupyterHub so I want to add e.g. the used image and version to the textbar after the image starts.
With JupyterHub, one idea could be to add a pre_spawn_hook
to the spawner and populate the settings files there. Similar to the bootstrapping example here: https://github.com/jupyterhub/jupyterhub/tree/master/examples/bootstrap-script
The image could be retrieved with spawner.image
.
@jtpio thanks for this great answer! I'm using the kubespawner and thus I got it working using the following extra config in the Helm chart config:
singleuser:
lifecycleHooks:
postStart:
exec:
command:
- "bash"
- "-c"
- >
mkdir -p /home/$NB_UID/.jupyter/lab/user-settings/jupyterlab-topbar-text/;
export IMAGE_VERSION=$(basename "$JUPYTER_IMAGE");
echo "{\"text\":\"$IMAGE_VERSION\"}" > /home/$NB_UID/.jupyter/lab/user-settings/jupyterlab-topbar-text/plugin.jupyterlab-settings;
Works like a charm!
Great, thanks for sharing this!
Is it possible to add text to the topbar-extension's text bar using a (config) file?
I'm using JupyterLab environments spawned by JupyterHub so I want to add e.g. the used image and version to the textbar after the image starts.