问题
Jupyter notebooks are awesome, and Colab provides a great way of sharing these to other developers. However, now I have a functionality in a Jupyter notebook that I would like to share with end users rather than developers. Backend there are various Python imports, 3D projections and solution of a non-linear optimization problem etc and I need to abstract that away from an end user. Due to its non-trivial functionality I would rather not have to port it to another language or at least not another platform, especially since it is already working.
The user interface for this functionality can however be very simple. A user should input two values, then see a plot and some text output.
What would be useful is if I could have a Colab document with a few forms or a widget that I could share using a shareable link. Anyone could open this document, enter two values, push a button and see the result. If many people open this document at the same time there could be problems, with conflicting user inputs. But there could be a work around to that? Opening the link and entering the values should be the only concern for the user. They should not have to push shift+enter to run a cell for instance. Double clicking a cell should not show any code. The Colab document should not have to be opened in Playground. I on the other hand wish not to have to put more effort into the web service business than sharing a Colab document from my Google Drive with people. At least nothing significantly harder than that.
Is this feasible, or do we still host a website etc to achieve such a functionality?
回答1:
Voila or the appmode module can change a Jupyter notebook into a webapp / dashboard-like interface. There is a gallery of Voila examples here so you can get a feel for what is possible. The main Voila repo is here. The main Appmode repo is here and describes it well. (Click launch binder
for an active example.) In addition, you may be interested in this discussion.
You can use the public MyBinder/Binder service to launch active sessions without needing to host a website. You can set up a public repository at Github (or several other places such as GitLab) and by connecting that to the MyBinder.org service via a URL that triggers launching that repo on a remote machine, you'll be able to share your functionality with others. For example, if you go here, and click launch binder
you get some active examples. (I recently helped someone with a simpler repo that launches one here, and that may give you a better idea of how easy it is to set up using the Binder system. You can do it all right in Github browser interface without needing to use git or anything locally.) There is a recent introductory video on using the Binder system by Serena Bonaretti here. The easiest way to see the options for where you can currently host your code and files is to go to the main MyBinder page and activate the drop-down menu on the left under GitHub repository name or URL
.
You can do the same with Appmode, see here for an example of using Appmode with the Binder service. It is possible to even edit the custom.js
file via the Binder system so you can hide the edit app
button, see here.
The Jupyter Discourse Forum is a good resource to ask for more help on Binder issues.
来源:https://stackoverflow.com/questions/59630751/simple-ui-on-top-of-colab