ideonate / cdsdashboards

JupyterHub extension for ContainDS Dashboards
https://cdsdashboards.readthedocs.io/
Other
200 stars 38 forks source link

Overwrite Voila template arg #10

Closed maarten-betman closed 4 years ago

maarten-betman commented 4 years ago

Hi! Firstly, awesome project!

Currently the Voila template argument defaults to 'materialstream'. Is there a way to overwrite the template argument set when launching Voila? Or do I have to make add a launcher to extra_presentation_launchers?

https://github.com/ideonate/cdsdashboards/blob/84069774ef3a8b630d1c3550f9871bf81e718bac/cdsdashboards/hubextension/spawners/variablemixin.py#L87-L92

danlester commented 4 years ago

@maarten-betman Thanks for your issue - it's great to hear you like the project!

To use that custom config to set the template for all Voila dashboards, you would just put something like this in your jupyterhub_config.py file (or e.g. config.yaml for k8s):

c.VariableMixin.voila_template = 'default'

(or if you feel it makes your config cleaner, you can specify the spawner you are using directly, e.g.)

c.VariableLocalProcessSpawner.voila_template = 'default'

VariableMixin is a superclass of VariableLocalProcessSpawner and the other similar spawners.

Anyway, that sets the template for all dashboards, but it would make sense to allow each dashboard publisher to set things like that for themselves at some point, on a per-dashboard basis. It's certainly a sensible feature suggestion.

For now, if you do want to be able to choose between different templates for different dashboards, you might also want to add an extra launcher in extra_presentation_launchers.

Perhaps make the main 'voila' launcher use the most-used template, as above, and then add something like the following to make a second voila framework using another template:

    extra_presentation_launchers = {
        'voila-template2': {
            #'cmd': ['python3', '-m', 'jhsingle_native_proxy.main'],  # This is the default cmd anyway
            'args': ['--destport=0', 'python3', '{-}m','voila', '{presentation_path}',
                '{--}port={port}',
                '{--}no-browser',
                '{--}Voila.base_url={base_url}/',
                '{--}Voila.server_url=/',
                '{--}template=template2']
        }

        c.CDSDashboardsConfig.extra_presentation_types = ['voila-template2']

Dashboard creators should then be able to choose between 'voila' and 'voila-template2' in the framework dropdown when they create a new dashboard.

If you are using DockerSpawner, you would just do:

c.CDSDashboardsConfig.extra_presentation_types = ['voila-template2']

and then in your singleuser Docker image you'd add an entrypoint-voila-template2.sh file.

Any problems, please just let me know more details about your setup, e.g. which spawner you are using, and where this goes wrong.