How to use ipywidgets in jupyter-notebook without Internet - jupyter-notebook

I have developed interactive application in python using jupyter notebook with ipywidgets and use voila to run the notebook.
On my development system (with internet) I have the application working flawlessly. But on the system without internet the application does not load. On inspection with developer tools, the web application is trying to load scripts from mathjax, font-awesome and here
If anyone could guide me on how to workaround this problem ? Run jupyter notebook application with ipywidgets without internet. Can we change some settings / configuration to use the static copy of these dependencies?
---- Update
On the system without internet, running jupyter lab and notebook and running the cells works perfectly fine. I am able to view the font-awesome icons and other ipywidgets. This issue is observed only using voila
Thanks in advance for your help.

Looks like we need to override the references to cdn and fontawesome in the templates of voila with local references.
Please find the reply from Jupyter discourse forum here.

I had the same issue about "font-awesome" icons which is not working with voila. To workaround it, I'm now using unicode characters in description strings instead of icon property.

Related

VScode showing raw source code instead of the remote jupyer notebook

I'm a bit puzzled of what goes wrong, and maybe someone here knows, or has had it before.
First, i got Docker on windows 11.
It runs a ubuntu python container, for all kind of AI stuff.
My local windows PC, has Vscode, i've made a connection to the local container (ssh).
When i open a .ipynb I see the raw file a Json like structure.
That is a bit strange because if i create a new ipynb on windows 11
Its is showing code/markdown cells normally like how vscode shows it normally.
VScode should know what Jupiter notebooks are
So Vscode knows python, everything seems installed in relation to jupyter and remote (localhost) connections.
Does anyone know perhaps what is going wrong here?.
Maybe its something i overlooked, missed.
Or some extra step that needs to be done at VScode, or i open it wrongly ?.
I open the file through the left pane open.. as shown:
I believe all related jupyter notebook stuff is installed in VScode
PS C:\python projects\test> code --list-extensions --show-versions
btwiuse.vscode-remote-server#0.0.5
colinfang.my-nbpreviewer#1.2.2
GitHub.copilot#1.56.7152
jithurjacob.nbpreviewer#1.2.2
ms-azuretools.vscode-docker#1.22.2
ms-dotnettools.csharp#1.25.0
ms-python.python#2022.16.1
ms-python.vscode-pylance#2022.10.40
ms-toolsai.jupyter#2022.9.1202862440
ms-toolsai.jupyter-keymap#1.0.0
ms-toolsai.jupyter-renderers#1.0.10
ms-toolsai.vscode-jupyter-cell-tags#0.1.6
ms-toolsai.vscode-jupyter-powertoys#0.0.6
ms-toolsai.vscode-jupyter-slideshow#0.1.5
ms-vscode-remote.remote-containers#0.255.4
ms-vscode-remote.remote-ssh#0.90.1
ms-vscode-remote.remote-ssh-edit#0.84.0
samghelms.jupyter-notebook-vscode#0.0.2

How to use shinyShortcut package on linux

I am trying to create an shiny app for people that are not R users (they even may be frightened :D).
After the question about server/local app here (How to import remote csv file on a deployed shiny app?), I try to use the shinyShortcut package solution.
I did the following:
devtools::install_github("ewan-keith/shinyShortcut")
library(shinyShortcut)
shinyShortcut(shinyDirectory = "/home/cha/Server",
OS = "unix")
then I got :
So I have all that is normally required (at least that is what I think).
Since I never used the .desktop before, I ran the instruction here.
I put the .desktop on my desktop
Right click and change setting the tutorial did
I allow again from a right click and the .desktop disappears. Everything seemed ok.
However, when I double-clicked on the icon, nothing happened...
I tried to change the web browser or the application to launch it, nothing works.
What did I misunderstand ?
Thanks in advance
Charlotte (Ubuntu 20.04)

Display Python code and Jupyter notebook on wix website

I'm writing a blog and I wanted to host a jupyter notebook on the wix website. What are the ways I can do it?
You can always turn your Jupyter Notebook to html that you can easily embed anywhere including Wix.
You can do it with this.

What is the easiest way to create a webapp from an interactive Jupyter Notebook?

I have a Jupyter Notebook that plots some data and lets the user interact with it via a slider.
What would be the easiest way to make a web app with a similar functionality? (reusing as much of the code...)
I believe the easiest way is to use voilà.
After installing you just have to run:
voila <path-to-notebook> <options>
And you will have a server running your notebook as a web app, with all the input code omitted.
AppMode is "A Jupyter extension that turns notebooks into web applications".
From the README:
Appmode consist of a server-side and a notebook extension for Jupyter.
Together these two extensions provide the following features:
One can view any notebook in appmode by clicking on the Appmode button in the toolbar. Alternatively one can change the url from
baseurl/notebooks/foo.ipynb to baseurl/apps/foo.ipynb. This also
allows for direct links into appmode.
When a notebook is opened in appmode, all code cells are automatically executed. In order to present a clean UI, all code cells
are hidden and the markdown cells are read-only.
A notebook can be opened multiple times in appmode without interference. This is achieved by creating temporary copies of the
notebook for each active appmode view. Each appmode view has its
dedicated ipython kernel. When an appmode page is closed the kernel is
shutdown and the temporary copy gets removed.
To allow for passing information between notebooks via url parameters, the current url is injected into the variable
jupyter_notebook_url.
To be complete - there exists also https://www.streamlit.io/ .
I still dont understand the exact difference between voila and streamlit.
At the moment I just struggle with the possibility to re-run everything with new parameters... I have bad luck with voila still.
Edit: I see that streamlit requires a raw python, not .ipynb, this fact would mean that this answer is completely wrong, I will search a bit more on streamlit before further action/comment.
Edit2: Voila looks great. However, I found few things that uncover the underlying complexity and thus a troubles that may arise.
callbacks. Widgets work great in jupyter, but since it is not possible to re-run one cell, sometimes the logic must be modified to work in Voila.
interactive java objects need a special treatment, e.g. matplotlib has a cheap solution, but there was nothing for e.g. jsroot
links. It is easy to create (a file and) a download link in jupyter, Voila can also serve a file, but it needs another extra treatment.
After all, I pose myself a question - is it better to learn many tricks and modifications to jupyter or to use some other system? I am going to see if streamlit can give em some answer.
The Jupyter Dashboards Bundlers extension from the Jupyter Incubator is one way to do it while retaining interactivity.
EDIT: While pip installing this package will also install the cms package dependency, like dashboard_bundlers, cms needs to be explicitly enabled/quick-setup as a notebook extension for the dashboard tools to work.
#raphaelts has the right idea and should be the accepted answer. As of Dec 2019, Voila is the most appropriate method to deploy Jupyter notebooks to production as a stand alone webapp. Think internal datascience teams sharing their analytics workload with internal C-Suite teams using SPA stlye Notebooks with all the code hidden and custom GUI/interactions thrown in. Recently discussed on HN
https://news.ycombinator.com/item?id=20160634 and the official announcement from the Jupyter maintainer https://blog.jupyter.org/and-voil%C3%A0-f6a2c08a4a93enter link description here
As mentioned above, voilà is a very powerful tool which hides the input cells from your notebooks and therefore provides a clean interface. In order to deploy your notebook with voilà you need to follow the specific steps of your organization. But if you want to quickly run it on your machine, simply install it with pip install voila. Then you can enter start from the command-line: voila my_notebook.ipynb or use the "Voila" button which should have appeared in your Jupyter notebook.
Note, however, that using voilà is only one part of the story. You also need to build the required interactivity, ie. to set up how to respond to input changes. There are quite a few frameworks for this.
The simplest one is to use the interact function or the observe method from the Ipywidgets library. This is very direct, but things can easily get out of control as you start having more and more widgets and complexity.
There are complete frameworks, some of them mentioned above. E.g. streamlit, dash and holoviz. These are very powerful and suited for larger projects.
But if you want to keep it simple, I also recommend to check out autocalc. It is a very easy-to-use library, which lets you define the dependencies between your widgets/variables and let all the recalculation be triggered automatically. A tutorial can be found here.
Disclaimer: I am the author of the autocalc package.
The easiest way is to use the Mercury framework. You can reuse all your code. To convert the notebook to web app you will need to add the YAML header in the first cell of the notebook (very similar to R Markdown). The widgets are generated based on YAML. The end-user can tweak widgets values and click the Run button to execute the notebook from the top to the bottom. You can easily hide the notebook's code (if you want) by setting the show-code: False in the YAML. The example notebook and corresponding web app are below.
Example of the notebook with YAML header
Example web app generated from notebook with Mercury

Jupyter notebook extension loading eratically

I load extensions to IPython notebook (powered by Jupyter) with the following command in ~\.ipython\profile_default\static\custom\custom.js.
IPython.load_extensions("calico-spell-check", "calico-document-tools");
The extensions are correctly loaded in the first notebook I open. But they are typically disabled in the following notebooks I open. Then when I close, reopen, etc. the notebooks they are loaded (seldom) or not (often) without any specific message in the console.
Is it a problem of compatibility with Jupyter or rather a bad configuration of mine?
You are hitting a race condition. Most of the instruction on how to activate extension in custom.js are wrong/too old when they tell you to directly copy past code in custom.js. Please follow official docs, use requirejs, and register the extension following the information in official docs.

Resources