ideonate / cdsdashboards

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

Whitelist File for Voila #89

Closed dipanghosh closed 2 years ago

dipanghosh commented 2 years ago

I have a notebook developed where the final result is meant to be downloaded by the end user. The files can get a bit large, so I want to avoid embedding the data into a button. So, I need to allow Voila to access files, and this can be done by whitelisting files on Voila. I read documentation and found that this can be done by modifying the presentation launcher like so:

c.VariableMixin.builtin_presentation_launchers = { 'voila': { 'args': ['--destport=0', 'python3', '{-}m','voila', '{presentation_path}', '{--}port={port}', '{--}no-browser', '{--}Voila.base_url={base_url}/', '{--}Voila.server_url=/', '''{--}VoilaConfiguration.file_whitelist="['.*']"''', '--progressive', ], } }

However, this does not seem to work. How can this be achieved?

danlester commented 2 years ago

I think you should be able to do this, but it's just about playing with the quote-escaping until it all gets through Python then passed into Voila via command line correctly...

There is a thread about it here where there seems to be a conclusion: https://gitter.im/ideonate/ContainDS?at=6017cd164f7d1b68e522dd4c

dipanghosh commented 2 years ago

I have tried all different combinations, but I was getting this error:

INFO:tornado.application:SuperviseAndProxyHandler http_get 44605 INFO:tornado.application:['python3', '-m', 'jhsingle_native_proxy.conda_runner', '/appl2/miniconda', '/appl2/miniconda/envs/analysis', 'python3', '-m', 'voila', '/appl2/dipan-python-scripts/jupyterhub/clustering/file_download_test.ipynb', '--port=44605', '--no-browser', '--Voila.base_url=/user/dipan.ghosh/dash-test-dl/', '--Voila.server_url=/', '--VoilaConfiguration.file_whitelist="[.*]"'] ERROR:tornado.application:b'/appl2/miniconda/envs/analysis/lib/python3.9/site-packages/traitlets/traitlets.py:2202: FutureWarning: Supporting extra quotes around strings is deprecated in traitlets 5.0. You can use \'[.*]\' instead of \'"[.*]"\' if you require traitlets >=5.\n

However, it is actually a matter of formatting the string correctly. what worked for me in the end was :

c.VariableMixin.extra_presentation_launchers = { 'voila': { 'args': ['--destport=0', 'python3', '{-}m','voila', '{presentation_path}', '{--}port={port}', '{--}no-browser', '{--}Voila.base_url={base_url}/', '{--}Voila.server_url=/', '{--}VoilaConfiguration.file_whitelist=[".*"]', '--progressive'], } }

There is a FutureWarning, but the functionality is fine.

ERROR:tornado.application:b'/appl2/miniconda/envs/analysis/lib/python3.9/site-packages/traitlets/traitlets.py:2562: FutureWarning: --VoilaConfiguration.file_whitelist=[".*"] for containers is deprecated in traitlets 5.0. You can pass--VoilaConfiguration.file_whitelist item... multiple times to add items to a list.\n