1

I try to create a simple weblink in Jupyter/Voila to display this:

display(HTML("""<a href="http://localhost:8888/XXX/transform/FINANICAL_ANALYSIS_MONTHLY.ipynb?month=current">Current Month</a> | 

As you can see I just hardcode the parameter:

?month=current

I am not able to retrieve these values in my notebook.

I have tried:

display(os.environ.get("SCRIPT_NAME"))

which gives: None and

sURL = os.getenv('HTTP_REFERER')

which gives None also this

import os

envs = {k: v for k, v in os.environ.items()} display (envs)

doesn't give the URL nor the parameters

Does someone have any idea how to get those ?

  • I was trying to work out something similar for using **in Voila** via MyBinder. See [here](https://discourse.jupyter.org/t/method-to-access-query-string-in-voila-notebook/5387/6?u=fomightez) for what so far has not been a solution for Voila. However, maybe it will help you though **since you want to access a query string from the URL in a notebook**? At least I think that, since you talk about not being able to retrieve values form inside a notebook. My demo in the top seems to do that & maybe it will work in your situation? (Although your title says you want to get it in Voila?) – Wayne Feb 07 '22 at 17:56
  • Thanks @Wayne I see how I can get the parameter in the jupyter notebook, but I would need to run the workbook again (Run All) etc. and voila breaks on that point, so I cannot use it at all. Any recommendation what I should try next? E.g. don't use Voila but... – user9093700 Feb 08 '22 at 08:52
  • Yes, at first I was really hoping because you wrote "I am not able to retrieve these values in my notebook", that you were looking to do this in a notebook. However, you were very close to the answer with that envs line. Pondering your question of how to run again made me realize that the solution that works in notebooks doesn't work in Voila partly because there is no URL where it runs because it runs things before it brings up the page. Then I reread https://github.com/voila-dashboards/voila/pull/414 and realized they had added a way but I had been not testing it right myself. – Wayne Feb 09 '22 at 04:02
  • 1
    I'm trying to put together a demo of the Voila-compatible way to access the `QUERY_STRING` now. That `envs` line that you listed last should yield the URL as well as the query string, among many other things. – Wayne Feb 09 '22 at 04:21
  • I made [a demonstration](https://discourse.jupyter.org/t/method-to-access-query-string-in-voila-notebook/5387/7?u=fomightez) using the notebook that had been linked to there before by ConorMc. – Wayne Feb 09 '22 at 05:51
  • 1
    Here is what I am using now: `pip install jupyter-notebookparams` and than a codecell with `# Parameters: level1 = "someword"` Last thing I had to solve was, that I pass a string, so I had to use %22: `level1=%22{x}%22` Still doesn't work in voila but with the &autorun=true option in the URL It executes the notebook right away. – user9093700 Feb 10 '22 at 09:40

0 Answers0