Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

passing arguments to Voila app #517

Open
jgunstone opened this issue Jan 17, 2020 · 4 comments
Open

passing arguments to Voila app #517

jgunstone opened this issue Jan 17, 2020 · 4 comments

Comments

@jgunstone
Copy link

I'm using Voila to build python apps internally for an engineering company.
It's awesome.

I'd like to know whether it is possible to pass arguments to a Voila App when it is initiated.
e.g.

voila app.ipynb inputdata.json

this would be a very useful feature as it would make it easy to interface a Voila App with other workflows.

@jtpio
Copy link
Member

jtpio commented Jan 24, 2020

Thanks @gunstonej.

Would these arguments be consumed in a notebook? That sounds similar to the prelaunch hook: #218

@johann-petrak
Copy link

I would very much need the same: pass on any number of program specific arguments to the notebook.

Maybe anything passed after the notebook filename could get ignored? Example: voila --debug --no-browser Voila01.ipynb --infile this.tsv --outfile that.tsv

Or, even better IMO, use a special argument separate like "--" to indicate that everything after that should get ignored:
voila --debug --no-browser Voila01.ipynb -- --infile this.tsv --outfile that.tsv

The second solution would make it easier to then parse the arguments within the notebook: one could ignore all elements in sys.argv up to and including "--" and then pass the rest to something like argparse.

@johann-petrak
Copy link

Sadly it seems there has not been any progress on this.
As I said, I think a solution where voila simply ignores everything after and including "--" or some other marker parameter would be trivial to implement and would allow to use sys.argv inside the notebook to get everyghin after the marker parameter as the app's own parameters, even parse them using argparse.

So far the only workaround is to use environment variables ...

@jgunstone
Copy link
Author

Hi @johann-petrak -

I agree that a CLI style interface would be great -
but I think that you can achieve a similar sort of thing in another way:

  1. use papermill to parameterize and then execute
    1.1. https://papermill.readthedocs.io/en/latest/usage-parameterize.html
    1.2. https://papermill.readthedocs.io/en/latest/usage-execute.html#execute-via-cli
  2. use the prelaunch hook as @jtpio suggested to inject a cell into the top of the notebook with the params you need:
    2.1. https://voila.readthedocs.io/en/stable/customize.html#creating-a-hook-function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants