pbugnion / ipywidgets_server Goto Github PK
View Code? Open in Web Editor NEW[unmaintained] Run Jupyter widgets outside of the notebook
Home Page: http://ipywidgets-server.readthedocs.io/en/latest/
License: Other
[unmaintained] Run Jupyter widgets outside of the notebook
Home Page: http://ipywidgets-server.readthedocs.io/en/latest/
License: Other
ipywidgets_server and QuantStack's excellent voila aim to do similar things.
Are they sufficiently similar that continuing development on both makes little sense? If the answer to that question is yes, I would prefer to halt development on this and redirect users to voila because I trust Sylvain will have the resources needed to do something great. What can ipywidgets_server do that voila can't?
I would love to hear thoughts from some of the people who have used ipywidgets server, if you have time (@DougRzz , @Juanlu001) and from @SylvainCorlay . And obviously anyone else who wants to chime in.
(Sorry, I don't have any experience with JS and HTML)
I've built a plotting widget in a Jupyter Notebook using bqplot
. It uses IPython.display.clear_output()
to redraw everything, which doesn't work on ipywidgets_server
. Is there any other way clear the output?
And is it possible to embed a widget from ipywidgets_server
in a web page?
Instructions for configuring a server to use ipywidgets_server would be great. Happy to help by at least trying the instructions out!
Is it possible to serve an interactive Bokeh plot? I have attempted to do this by creating a html file from Bokeh and passing it to a html ipywidget but this widget will not render such a complicated html string. Do you have any ideas of how this may be done ?
Ideally, shutting down the app should also shut down the kernel and the frontend. At the moment, the frontend just tries to reconnect to the kernel. This causes a stacktrace when a new version of the app is started.
The recent versions of ipyvolume don't seem to work with ipywidsgets-server. There are no error messages and the screen just stays blank. I downgraded the version of ipyvolume which i know used to work but there still seems to be a problem so it might be my Python installation.
Here is an example which i took from the ipyvolume documentation.
ipywidgets-server ipyvolumeExample:vbox
ipyvolumeExample.zip
ipywidgets-server ipyvolumeExample:vbox
Hi, ipywidgets-server has been incredibly useful this year. Thanks for the great tool.
I have been using Ipyevents with BQplot which allows me to trigger events from mouse control. However, it doesn't seem to work with ipywidgets-server. See the animation and example posted in bqplot/bqplot#729 (comment)
The add toggle button should allow scatter points to be added to the heatmap.
Also, some jslinks did not work. See commented out jslinks in the python script. This shoulkd probably be logged as a seperate issue.
ipywidgets-server BQplotHeatmap_ipyevents:vbox
BQplotHeatmap_ipyevents.zip
Hi, when using ipywidgets.Tab, all the children objects are shown in all the tabs spaces.
This example works well in a notebook, but not via ipywidgets-server
#!/usr/bin/env python
import ipywidgets as w
text1 = w.Text(description='Text 1')
text2 = w.Text(description='Text 2')
text3 = w.Text(description='Text 3')
tab = w.Tab([text1, text2, text3])
for i, v in enumerate(tab.children):
tab.set_title(i, v.description)
May you take a look?
Thanks!
Hi,
I'm having issues installing ipywidgets_server: It says the version of Python is not correct, and I'm using Python 3.6 as requested.
(base) C:\Users\nma>pip install ipywidgets_server
Collecting ipywidgets_server
Could not find a version that satisfies the requirement ipywidgets_server (from versions: )
No matching distribution found for ipywidgets_server(base) C:\Users\nma>python --version
Python 3.6.5
Could you please help?
Regards
Nicolas
If the client shuts down gracefully, the kernel is shutdown. However, if the client crashes, or terminates abruptly, the kernel remains alive, using up resources on the server.
We should implement a keep-alive mechanism, where the client periodically sends messages to either the server or the kernel to indicate that it's still alive. We should look at the following:
PUT /api/kernels/%s/keepalive
) or in the kernel? I'm inclined to think the server is better -- specially if we want to support additional kernel types in the future. If we're putting it in the server, that may mean extending the kernel manager?The client takes no remedial action when the websockets close. This can be confusing to a user, since the app looks normal.
I think the easiest way of implementing this is to watch the websocket connection client-side, and react to it being closed. The JupyterLab kernel client that we use already supports monitoring a rich set of kernel events that we can just hook into.
To try these out, add this to WidgetApplication.js
just after the kernel is created.
this._kernel.statusChanged.connect((sender, msg) => console.log(msg))
If you interrupt the server, you can see that the status goes to reconnecting
, then, after 2 minutes, the status goes to dead
. When the status becomes dead
, we want to take some remedial action.
For the actual implementation of the modal, we can probably use the Dialog
class from @jupyterlab/apputils
.
I'm experimenting with the Dash framework (from plotly guys) and they made it very easy to deploy the app on Heroku. But I really prefer ipywidgets + bqplot.
So, I was wondering whether it is also already possible to use ipywidgets_server on Heroku. And, in the case of a positive answer, if you could point to some model I could follow.
Just a little background: I'm a economics/statistics professor in Brazil, mostly dealing with students familiar with R's Shiny. So, although ipywidgets is awesome to work in the classroom, the ability to share the applications built by the students with non-coding people as easily as with Shiny is a sad limitation in our ecosystem.
Appmode is a step in that direction, with the benefit of free hosting on github/mybinder, but with the limitations of mybinder bandwidth. Dash is another another step, with the limitation of not using using ipywidgets/bqplot and the benefit of easily deploying on the free tier of Heroku (the proof of the easiness is that they made me deploy my very first apps).
Sorry if my question is silly or misplaced, but I have the impression that your work is in a position to fill a huge gap. Thank you very much.
How can you embed ipywidgets-server output in a webpage?
Originally raised as part of issue #39 .
Hi ,While launching the server at a port , I am gettng an error message of Error aborted 404 on main.js " i.e. 'Failed to load resource: the server responded with a status of 404 (), /main.js not found
in console.
I am not able to figure out why its not able to load properly.
Do anyone has an idea what I am doing wrong ?
PS : I am loading it over the https. I have integrated with my product . The error is coming from the external script that u including in index.html <script data-main="/main" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js" integrity="sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA=" crossorigin="anonymous"> </script>
This file is giving me error main.js not found in my env .
I have noticed main.js script tag is dynamically comes in html and that path is getting wrong , So can u suggest me how to change that path , bcz there it is /main.js which is wrong in my case .
Any advice on how to resolve this ? I m in great need..
Hi, I love this package. I was going to try and figure out the JupyterWidgets web3 example this weekend but instead, ipywidgets-server made it very easy. Thanks!
So far I have just 1 minor issue. I tried a bqplot example (see code below) using the command
ipywidgets-server bqPlotExample:vBoxPlot
This is the same as the example shown in bqplot/bqplot#316 (comment). The buttons icons which uses font-awesome fonts are not showing when I run in ipywidget-server. Do you know how this can be fixed? Thanks, Doug
from bqplot.interacts import PanZoom
import ipywidgets as widgets
import bqplot as bq
from traitlets import link
from collections import OrderedDict
import numpy as np
buttonWidth = '50px'
x_sc = bq.LinearScale()
y_sc = bq.LinearScale()
x_data = np.arange(500)
y_data = np.random.randn(3, 500)
line_chart = bq.Lines(x=x_data, y=y_data, scales= {'x': x_sc, 'y': y_sc},
display_legend=True, labels=["line 1", "line 2", "line 3"] )
ax_x = bq.Axis(scale=x_sc)
ax_y = bq.Axis(scale=y_sc, orientation='vertical', tick_format='0.2f')
fig = bq.Figure(marks=[line_chart], axes=[ax_x, ax_y])
fig.layout.width = '95%'
pz = PanZoom(scales={'x': [x_sc], 'y': [y_sc]})
pzx = PanZoom(scales={'x': [x_sc]})
pzy = PanZoom(scales={'y': [y_sc], })
#
zoom_interacts = widgets.ToggleButtons(
options=OrderedDict([
('xy ', pz),
('x ', pzx),
('y ', pzy),
(' ', None)]),
icons = ["arrows", "arrows-h", "arrows-v", "stop"],
tooltips = ["zoom/pan in x & y", "zoom/pan in x only", "zoom/pan in y only", "cancel zoom/pan"]
)
zoom_interacts.style.button_width = buttonWidth
ResetZoomButton = widgets.Button(
description='',
disabled=False,
button_style='', # 'success', 'info', 'warning', 'danger' or ''
tooltip='Reset zoom',
icon='arrows-alt'
)
def resetZoom(new):
# Reset the x and y axes on the figure
fig.axes[0].scale.min = None
fig.axes[1].scale.min = None
fig.axes[0].scale.max = None
fig.axes[1].scale.max = None
ResetZoomButton.on_click(resetZoom)
ResetZoomButton.layout.width = buttonWidth
link((zoom_interacts, 'value'), (fig, 'interaction'))
vBoxPlot = widgets.VBox([fig, widgets.HBox([zoom_interacts,ResetZoomButton])], align_self='stretch')
!
It would be good to have one or two examples of bqplot and ipyvolume.
I think the following make for a good example:
There are some new widgets (e.g. FloatLogSlider
) that aren't included in the javascript bundled with the last release of ipywidgets_server
. Looks like a new release (and maybe bumping the minimum npm version of @jupyter-widgets/controls
) will do the trick.
This code snippet will demonstrate the problem; when you try connecting to port 8866 you just get a blank page, and errors in the console about not being able to find FloatLogSliderModel
:
# Add a slider to allow adjusting MS distance brightness
from ipywidgets import FloatLogSlider
initial_dist = 10
dist_slider = FloatLogSlider(base=10, min=1, max=4, step=0.01,
description='Distance (pc)', value=3,
readout_format='d')
Pinging @JuanCab who found the issue.
Hi , In your widget you have mentioned that for loading the widget user needs to enter the url like http://127.0.0.1:8866
, I wonder why localhost not works instead for 127.0.0.1
? I tried entering url like http://localhost:8866
, It give me following error : serverconnection.js:172 GET http://localhost:8866/api/kernelspecs?1541748996695 403 (Forbidden)
If I want to host this application on my secure domain , would it be possible that this work ?
At the moment, a kernel is started whenever a client connects. This does not work well if the initial start-up time of the kernel is long.
We should maintain a cache of preheated kernels that we can just attach to clients as needed.
Maybe kernel_gateway has some useful patterns that we can copy.
At the moment, we include the Bootstrap CSS. This changes the behaviour of other CSS rules on the page. In particular, since Bootstrap is not included in the ipywidgets embed by default, including bootstrap here leads to slight differences in layout.
For instance, the buttons in the example of issue #6 are not aligned.
The only reason Bootstrap was included was to access the grid layout. We can reproduce this manually without resorting to Bootstrap.
The accordion widget doesn't collapse down. The example below works in Jupyter but not in ipywidgets-server.
import ipywidgets as widgets
accordion = widgets.Accordion(children=[widgets.IntSlider(), widgets.Text()])
accordion.set_title(0, 'Slider')
accordion.set_title(1, 'Text')
accordion
vbox = widgets.VBox([accordion])
By comparison to the web3
example from ipywidgets, this repository provides guarantees of security: it should not, in principle, be possible for someone (client-side) to get the kernel to execute arbitrary code.
Some unit tests for this would go a long way to making this project more production-ready.
I have noticed that if I load up a ipywidgets-server dashboard from the browser it starts a new Python kernel process ... as expected. A new kernel is started everytime a new session is opened up in the browser or if the browser page is refreshed. However, redundant Python processes are not shutdown. This is causing a proliferation of unused kernels which consume memory. Would it be possible to automatically close Python kernels which are no longer active? Maybe the Python kernel could periodically ping the browser to check it is still active.
N.B. My ipywidgets_server is running on:
At the moment, this repository uses some Python 3.6 and Python 3.x only features (pathlib, f-strings etc.). Ideally, we should also support Python 2.
Hi, I am trying to break your code but I have failed! I am very impressed. Basically, it can be used as an very effective dashboarding app for Jupyter. I have tested it with numerous widgets including several buttons, select widgets and Bqplot line & bar charts together with Vaex for large datasets and I have had no real issues. I have had to re-factor my Jupyter code a bit for it to work. This included removing any ipython.display commands. None of it a big deal.
I have noticed that there seems to be a limit in the total height allowed in the webpage area. If I zoom in the Chrome browser, the upper widgets disappear and the vertical scrollbar doesn't allow me to navigate to the upper display area. Did you create a hard limit for the height?
You should be able to pass in your own custom HTML template.
(because everyone loves customisation!)
Hi , I am using IPywidgets-server inside a Docker container. I have installed the Ipywidgets-server module by pip, added the python file in a folder from where it will be run (as per the documentation). Now I am running a bash script by the docker ENTRYPOINT that will execute the bash script having command "ipywidgets-server file_name: container" and then by docker networking I am exposing the port to be used at the client end. But I am facing a Error:No module named file. Can anyone help me?
PS: Any suggestion to it in a different way.
Thanks in Advance
Vidit
There seems to be a conflict with a beakerx table and customisation settings in ipywidgets-server ( defined in the \static\index.html). I define the width of the web app to be 90% of the page but with a beakerx table, the width returns to the default. Do you have any suggestions on how i can get around this issue? Should i be asking the beakerx team?
Hi, firstly I would like to say that ipywidgets-server has really helped me out and works very well. This project deserves more publicity and stars.
It would be great to be able to serve with 1 click from a Jupyter/Jupyterlab notebook. However, I am not sure how to create a Jupyter extension. I have an alternative....I have been automatically converting my notebook session and serving it with ipywidgets-server using the code below. This was placed in the last 4 cells of my notebook. Perhaps this code could be used as a basis for a Jupyterlab extension sometime in the future.
%%javascript
var nb = IPython.notebook;
var kernel = IPython.notebook.kernel;
var commandFileName = "notebookPath = " + "'"+ nb.notebook_path +"'";
kernel.execute(commandFileName);
import nbformat
from nbconvert import PythonExporter
import os
import re
import socket
from contextlib import closing
findFreePort = False
defaultFreePort = '39393' # If findFreePort is False, set this number to desired free port. Else find a free one.
widgetName = 'vbox'
# Read current ipynb notebook
with open(notebookPath) as fh:
nb = nbformat.reads(fh.read(), nbformat.NO_CONVERT)
exporter = PythonExporter()
# Convert ipynb to Python
source, meta = exporter.from_notebook_node(nb)
#USe a regex to remove bottom of py file which includes everthing below first magic command
lines=re.sub("get_ipython\(\).*","",source, flags=re.IGNORECASE|re.MULTILINE|re.DOTALL)
# Write Python script
file_fullPathName=os.path.join((os.getcwd()), notebookPath.replace('.ipynb', '.py'))
# file_fullPathName=os.path.join(directory, notebookPath.replace('.ipynb', '.py'))
with open(file_fullPathName, "w") as outp:
outp.write(lines) #Write model data File (upto step)
def find_free_port():
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
s.bind(('', 0))
return s.getsockname()[1]
if findFreePort:
freePort = str(find_free_port())
else:
freePort = defaultFreePort
ipaddress = socket.gethostbyname(socket.gethostname())
#Open from command window from windows. Doesn't work
commandServe = "ipywidgets-server --port " + freePort + " " + notebookPath.replace('.ipynb', '') + ':' + widgetName
print(commandServe)
urlAddress = ipaddress + ":" + freePort
print(urlAddress)
# Windows OS: Open command window and serve ipywidgets
commandServeWinOS = "start cmd.exe /c @cmd /k \"" + r"C:\Users\\" + os.getlogin() + "\AppData\Local\Continuum\miniconda3\Scripts\ipywidgets-server.exe --port " + freePort + " " + notebookPath.replace('.ipynb', '') + ':vbox\"'
print(commandServeWinOS)
os.system(commandServeWinOS)
import webbrowser
# generate an URL
webbrowser.get("C:/Users/" + os.getlogin() + "/AppData/Local/Google/Chrome/Application/chrome.exe %s").open("http://" + urlAddress)
# webbrowser.get("C:/Users/" + os.getlogin() + "/AppData/Local/Mozilla Firefox/firefox.exe %s").open("http://" + urlAddress)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.