GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together. Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community. Already on GitHub?
Sign in to your account. Using latest bokeh any CustomJS callbacks added after an app is initialized do not seem to ever be called.
In the example below for instance we add a button which when clicked should add a JS callback triggered when the selection changes a contrived example I know. However a change in the selection does not trigger the console. I have checked that the event is sent but haven't yet dug into what happens to the callback on the BokehJS end. Skip to content.
Dismiss Join GitHub today GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I am trying to display a bar chart and have the contents filtered by a Select object. As simple as it seems, I have not been able to find a working solution after two days of looking.
EDIT: No, no bug. The issue was that the Select was defined after the callback, and since things were in the notebook, it was using the value from the previous cell execution. Unfortunately the intrinsic nature of the notebook makes issues with corrupted state very easy to achieve, in general. As a final note I will mention that learning to check the browser's JS console is indispensable for debugging CustomJS type callbacks.
The errors from your code showed up there immediately. Learn more. Asked 3 months ago. Active 3 months ago. Viewed times. Here is the code I am trying, but when I run it nothing is displayed, not even an empty plot. Active Oldest Votes. Thank you, that gets me closer, but the result has two issues. The first is that the initial plot when no selection has been made yet appears but is blank, and has a bunch of tiny text crammed into the upper left corner of the grid.
Alternatively you can choose to one of the categories to start with so that there is data present at the start. The range issue is a separate question. Sign up or log in Sign up using Google.
Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.Skip to content. Permalink Browse files. Allows to add a CustomJS callback to any backbone event. Loading branch information. Unified Split. Showing 13 changed files with additions and 50 deletions.
Documents contain collections of related Bokeh Models e. One thing to keep in mind is that a Viewable should have a single unique representation in the persistence layer, but it might have multiple concurrent client-side Views looking at it. Those may be from different machines altogether. This name can be useful when querying the document to retrieve specific Bokeh models.
This data can be useful when querying the document to retrieve specific Bokeh models String ] tags : [ p. Oops, something went wrong. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Bokeh Documents. Documents contain collections of.
One thing to keep in mind is that a Viewable should have a single. Those may. An arbitrary, user-supplied name for this model. This name can be useful when querying the document to retrieve specific. Bokeh models. No uniqueness guarantees or other conditions are enforced on any names. An optional list of arbitrary, user-supplied values to attach to this.
This data can be useful when querying the document to retrieve specific. Bokeh models:.Hello, I am trying to run Bokeh visualizations inside a Django framework. The goal is for the user to import a csv file, which, when uploaded, renders an html with bokeh plots that I have specified. I have successfully built the views and connected the urls properly, and my plot renders after the csv is uploaded.
Here is the relevant code snippet:. I am not sure about the Django aspect of your issue or if any others exist given the excerpt of code provided.
However, the following points might be relevant. And the following line is registering it as a Python callback. So while it is consistent to register a Python function as a Python callback, an implication is that you need to be running bokeh as a server for it to work. I do not have any issues with the django aspect of this project. The problem is as you mentioned: python callbacks are not registered in a standalone HTML file.
I am aware that another solution to this issue is to run a bokeh server within my django app, but creating a dynamic html file using CustomJS seems like a much simpler option. I see. I misread that you were wondering why the code excerpt provided in the example did not work and perhaps you were thinking you were running with a JS callback when that is not the case.
The following is a basic example to help illustrate. It covers the functional requirements you need but leaves the implementation details to how you want to modify the data in your specific application to you.
And the following line is registering it as a Python callback So while it is consistent to register a Python function as a Python callback, an implication is that you need to be running bokeh as a server for it to work.GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together. Have a question about this project?
Sign up for a free GitHub account to open an issue and contact its maintainers and the community. Already on GitHub? Sign in to your account. Button widgets, when disabled, still invoke their callback function when clicked. Using the example code below, the message 'Start button was clicked' can be seen in the browser console when the disabled button is clicked. I remember having a conversation about this exact thing while I was working on the layout work, but I can't find it quickly.
Maybe it was on the mailing list. I have some vague notion that it came up that the event was desirable. But I remember thinking exactly the same thing - if the button's disabled it shouldn't fire events. From my perspective, while I concede that there might be cases where firing the callback would still be desirable, I expected the default behaviour to be that disabling the button disables the callback.
Perhaps if there was an attribute for the widget, called e. IMO disabled widgets should be greyed, non-interactable, and as a consequence never fire callbacks. I'm not sure what "disabled" would mean otherwise. I experienced that disabled isn't respected Toggle in particularwhich tripped me up given the documentation of the disabled parameter: "If True, the widget will be greyed-out, and not respond to UI events.
I realize you guys only have so much time and a priority list. I want to get a rough idea of when it might be addressed, for my own planning using Bokeh on a project that is subject to deadlines. In the meantime, I'll work around it Thanks guys!Bases: bokeh. This is an abstract base class used to help organize the hierarchy of Bokeh model types. It is not useful to instantiate on its own. A mapping of event names to lists of CustomJS callbacks. Typically, rather then modifying this property directly, callbacks should be added using the Model.
A mapping of attribute names to lists of CustomJS callbacks, to be set up on BokehJS side when the document is created. No uniqueness guarantees or other conditions are enforced on any names that are provided, nor is the name used directly by Bokeh for any reason. List of events that are subscribed to by Python callbacks. This is the set of events that will be communicated from BokehJS back to Python for this model.
Or simply a convenient way to attach any necessary metadata to a model that can be accessed by CustomJS callbacks, etc. No uniqueness guarantees or other conditions are enforced on any tags that are provided, nor are the tags used directly by Bokeh for any reason.
Collect the names of all DataSpec properties on this class. This method always traverses the class hierarchy and includes properties defined on any parent classes.
Collect a dict mapping the names of all DataSpec properties on this class to the associated properties. This is a convenience method that simplifies adding a CustomJS callback to update one Bokeh model property whenever another changes value. ValueError —.
Interactive Histograms with Bokeh
As a convenience, if the event name passed to this method is also the name of a property on the model, then it will be prefixed with "change:" automatically:. However, there are other kinds of events that can be useful to respond to, in addition to property change events. For example to run a callback whenever data is streamed to a ColumnDataSourceuse the "stream" event on the source:. Find the PropertyDescriptor for a Bokeh property on a class, given the property name.
Add a callback on this object to trigger when attr changes. This method optionally traverses the class hierarchy and includes properties defined on any parent classes.
Query the properties values of HasProps instances with a predicate. Returns all Models that this object has references to. Query this object and all of its references for objects that match the given selector. Raises an error if more than one object is found.
Returns single matching object, or None if nothing is found :param selector: :type selector: JSON-like. In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating.
This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself. Results are returned as a dict from property name to value, or None if no theme overrides any values for this instance. References to other objects are serialized as references just the object ID and type infoso the deserializer will need to separately have the full attributes of those other objects.
Note that in addition to the code property, CustomJS also accepts an args property that maps string names to Bokeh models. Additionally, the model that triggers the callback i.
The full format for a property change event is, e. Additionally, some Bokeh models have additional specialized events. For example, the ColumnDataSource also supports "patch" and "stream" events, for executing CustomJS callbacks whenever the data source is patched or streamed to. Below is an example that shows how to attach a CustomJS callback to a Slider widget, so that whenever the slider value updates, the callback is executed to update some data:.
The event can be specified as a string such as 'tap' above, or an event class import from the bokeh. The following code imports bokeh. The result is a plot that when interacted with, displays the corresponding event on the right:. A common use case for property callbacks is responsing to changes to widgets. The code below shows an example of CustomJS set on a slider Widget that changes the source of a plot when the slider is used.
Another common scenario is wanting to specify the same kind of callback to be executed whenever a selection changes. As a simple demonstration, the example below simply copies selected points on the first plot to the second. However, more sophisticated actions and computations are easily constructed in a similar way. Another more sophisticated example is shown below. It computes the average y value of any selected points including multiple disjoint selectionsand draws a line through that value.
The properties of range objects may also be connected to CustomJS callbacks in order to perform specialized work whenever a range changes:. Selection tools emit events that can drive useful callbacks. In addition to the generic mechanisms described above for adding CustomJS callbacks to Bokeh models, there are also a some Bokeh models that have a. The callbacks described below were added early to Bokeh in an ad-hoc fashion. Many of them can be accomplished with the generic mechanism described above, and as such, may be deprecated in favor of the generic mechanism in the future.
The HoverTool has a callback which comes with two pieces of built-in data: the indexand the geometry. The index is the indices of any points that the hover tool is over. Opening an URL when users click on a glyph for instance a circle marker is a very popular feature. Bokeh lets users enable this feature by exposing an OpenURL callback object that can be passed to a Tap tool in order to have that action called whenever the users clicks on the glyph.