I have a Bokeh chart in a Jupyter notebook, and I want to run custom Python whenever the Bokeh selection changes. It is very easy to run custom Javascript whenever the Bokeh selection changes using a source change callback, but I have no way to trigger Jupyter to respond to the event.
I think it is possible but poorly documented (see http://docs.bokeh.org/en/latest/docs/user_guide/server.html) to run a separate Bokeh server to receive the events. I want to avoid running a separate Bokeh server since the Jupyter server is already running.
I think you have to look at holoview.
It is design for this. You can choose between different renderers : matpotlib, bokeh, plotly.
You can either use their methodology for simple plots or if it is more specific you can run bokeh apps.
As you can see almost all examples of bokeh are ported to holoviews
Regards
This seems like a two-way communication between Bokeh object and Jupyter: https://docs.bokeh.org/en/latest/docs/user_guide/jupyter.html#notebook-handles
Import standard functions and push_notebook()
Create some plots and pass notebook_handle=True to show()
Check that the handle is associated with the output cell
Update some properties of the plot, then call push_notebook() with the handle
Note that the output cell has changed (without being re-executed)
You might have to poll the variable you want to catch changing, as this does not look like an event handler, just mutual exposure.
Related
I have a current project that consists of 3 parts:
An interface for clients to upload datasets from their equipment.
Process the uploaded datasets using R and some preset coefficients.
Display in a graph with a regression line, allowing the user to click points on the graph to remove them where needed and redraw the regression line automatically (after point removed).
Part 1: This is already done using PHP/Laravel. A simple upload and processing interface.
Part 3: I've been able to set this up in chart.js without any problems.
Part 2 is the sticking point at the moment. What I'd like is to be able to send the data to an rscript and just get the datapoints back so that I can display them. Can anyone give suggestions as to the best way to do this? Is there an api available? Or do I need to install software on the server (not an issue if I do, but I'm hoping to avoid the need to if possible)?
TIA
Carton
There is the package shiny to do everything in R (user side GUI and server side R processing). Since you did it in PHP already, you can either write an R script that is being executed with a shell call from PHP, or build an R REST API with plumber
I have two gpus, and want to open a second juptyer notebook and ensure everything within it runs only on the second gpu rather than the first. Ideally I'd like to do this by running a cell at the start rather than passing device=1 in multiple places.
The answer in this scenario is to call set device.
import torch
torch.cuda.set_device(1)
The docs however discourage it. According to the github note on the checkin (https://github.com/pytorch/pytorch/issues/260) my scenario is the only reasonable use case. The preferred method is to set an environment variable, which is also possible in the notebook case:
import os
os.environ['CUDA_VISIBLE_DEVICES']='1'
Is it possible to have custom bokeh models displayed inside jupyter-lab or notebooks? Currently, I get an Javascript Error when trying to do so, e.g. evaluating the Custom Draw Tool example inside a notebook, bokeh will complain about:
Javascript Error: Model 'DrawTool' does not exist. This could be due to a widget
or a custom model not being registered before first usage.
Yes, it is possible. But you will need to call output_notebook again (or for the first time) after you define the custom model. Otherwise it will not be registered with the BokehJS runtime (i.e. BokehJS will not know it exists).
What would it take to implement a tree diagram in bokeh? Something similar to this DS example would be nice --
http://bl.ocks.org/robschmuecker/7880033
I'm just looking to visualize a data structure, so only need the pan, zoom, and collapse functionality.
Thanks!
- AH
There is nothing in Bokeh to do this automatically. Bokeh does now support network/graph support, which it did not at the time the question was originally posted:
https://docs.bokeh.org/en/latest/docs/user_guide/graph.html
However, it would take some work to use this to reproduce the link above:
non straight-line edges would need to be computed explicitly
nodes/edges would have to be hidden manually based on TapTool events
Additionally there is no "smooth animation" option yet (as of Bokeh 0.13.0) so the transitions would be instant.
If the idea is to have this sort of capability along side other Bokeh plots, or to connect it to Python backend code, then another option is to write a custom extension for Bokeh:
https://docs.bokeh.org/en/latest/docs/user_guide/extensions.html
This would take some up-front work, but doing this, you could integrate the fancy D3 widget directly into Bokeh documents, and use it like, and connect it to, any other Bokeh component or widget.
My scenario here is the following: I am using a pyqt widget to display a solid color fullscreen on a second display and observe this display with a camera that is continuously capturing images. I do some processing with the images and this is the data I am interested in. This works great when used interactively with ipython and matplotlib using the qt4agg backend like so
% ipython -pylab
# ... import PatternDisplay, starting camera
pd = PatternDisplay(); pd.show(); pd.showColor(r=255,g=255,b=255)
imshow(cam.current_image)
I need a similar behavior now in a console script though: it should display the PatternDisplay widget, capture an image, than change the color on the PatternDisplay and take a new image and so on.
The problem is now that the PatternDisplay is never updated/redrawn in my script, likely because PyQt never gets a chance to run it's event queue. I had no luck trying to move the linear worker part of my script into a QThread because I cannot communicate with the PatternDisplay Widget from another Thread any longer. I tried to replicate the implementation of ipython/matplotlib, but I didn't fully understand it, it is quite complicated - it avoids running the QApplication main loop via monkey patching and somehow moves QT into it's own thread. It then checks periodically using a QTimer if a new command was entered by the user.
Isn't there an easy way to achieve what I want to do? I am gladly providing more information if needed. Thanks for any help!
What you need is easier than IPython's job - IPython makes the Qt application and the command line interactive at the same time.
I think the way to do it in Qt is to use a timer which fires at regular intervals, and connect the signal to the 'slot' representing your function that gets the new image and puts it in the widget. So you're pulling it in from the event loop, rather than trying to push it.
I've not used Qt much, so I can't give specifics, but the more I think about it, the more I think that's the right way to do it.
I solved the same problem (i.e. interactive ipython console in terminal, and GUI thread running independently) in the following way with ipython 0.10 (code here)
1. Construct QApplication object, but don't enter its event loop explicitly
2. Run the embedded IPython instance
3. Run the UI code you need by instantiating your window and calling show() on it (like here with the yade.qt.Controller(), which I aliased to F12. (I did not find a way how to ask the embedded shell to run a command at the start of the session, as if the user had typed it)
(You can also show() your window first, then run the embedded ipython. It will provide event loop for Qt.)
(BTW I also tried running Qt4 from a background thread (using both python threads module, and Qt4.QThreads), but it refuses to run in such way stubbornly. Don't bother going that way.)
The disadvantage is that UI will be blocked while ipython is busy. I hope to finding something better for 0.11, which should have much better threading facilities (I asked on ipython-users about how to unblock the UI).
HTH, v.