question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Better warn about passing source in the CustomJSFilter args dict for 2.0 and above

See original GitHub issue

The requirement to no longer specify source in the args dict tripped me (a layman) up when using a script that worked in 1.40 in 2.0.2. I couldn’t work out what was wrong so I asked in a StackOverflow thread where @bryevdv explained what was going on, updated his previous example, and asked me to create this issue.

Here’s the previous code which didn’t work, and the only change was source=source added:

from bokeh.plotting import figure, show
from bokeh.models import Slider, CustomJSFilter, CDSView, ColumnDataSource, CustomJS
from bokeh.layouts import column, layout

data = dict(Flights=[97, 34, 23, 6, 26, 97, 21, 92, 73, 10, 92, 14, 77, 4, 25, 48, 26, 39, 93],
            Not_Cancelled=[87, 63, 56, 38, 57, 63, 73, 56, 30, 23, 66, 47, 76, 15, 80, 78, 69, 87, 28],
            OnTime_Arrivals=[21, 65, 86, 39, 32, 62, 46, 51, 17, 79, 64, 43, 54, 50, 47, 63, 54, 84, 79])
source = ColumnDataSource(data=data)

MinFlights = Slider(start=0, value=50, end=100, step=1)

# this filter selects rows of data source that satisfy the constraint
custom_filter = CustomJSFilter(args=dict(slider=MinFlights), code="""
    const indices = []
    for (var i = 0; i < source.get_length(); i++) {
        if (source.data['Flights'][i] > slider.value) {
            indices.push(true)
        } else {
            indices.push(false)
        }
    }
    return indices
""")
view = CDSView(source=source, filters=[custom_filter])

# force a re-render when the slider changes
MinFlights.js_on_change('value', CustomJS(args=dict(source=source), code="""
   source.change.emit()
"""))

p = figure()
p.circle('OnTime_Arrivals', 'Not_Cancelled', source=source, view=view, size=20)

inputs = column(MinFlights, width=200)
show(layout([[inputs,p]]))

I’m unsure what solution to this would’ve been best but at least for me a simple warning that source=source is no longer required in CustomJS as of 2.0 would’ve been helpful.

First time creating an issue here so please let me know if I’m doing anything wrong or could better explain something. Unsure if this is a bug but didn’t know what else to set it as.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bryevdvcommented, Jan 2, 2021

@cyborg1995 The args property for CustomJSFilter is currently defined as a plain (bokeh) Dict property:

https://github.com/bokeh/bokeh/blob/f91a3a668ea3ee39e02eee2fc46bba759b8395ab/bokeh/models/filters.py#L105-L109

But users should not really ever pass a source key in this dict, because CustomJSFilter already automatically provides aa source value on its own. So I proposed the idea of creating a new property type that can disallow specified keys, e.g something like

args = RestrictedDict(String, AnyRef, disallow=("source", ), help=...)

The definition of Dict is here:

https://github.com/bokeh/bokeh/blob/531452908b70f7eeb128c955aebe2e4247e5ee08/bokeh/core/property/container.py#L156

I think it would suffice to simply subclass Dict and supply a new validate method that checks the user-supplied keys against the self.disallow list of keys and raises an error if a disallowed key is present (it would need to call the super validate method too, of course). New unit tests would also need to be added here:

https://github.com/bokeh/bokeh/blob/531452908b70f7eeb128c955aebe2e4247e5ee08/tests/unit/bokeh/core/property/test_container.py

elaborate on what you mean by ‘Document validation check’

Let’s focus on the property-based solution described above, instead of a document validation approach.

I’m new to open source and bokeh

We’d love to have your contribution, it’s probably worth just exploring Bokeh as a user first a little, there are some tutorials linked from the main GitHub and docs pages.

0reactions
cyborg1995commented, Jan 4, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to link Bokeh inputs / controls to filter data? Can't work ...
A source parameter is already implicitly passed in by Bokeh, so passing in again in the args dict is the problem. This stopped...
Read more >
Source code for bokeh.models.filters - Bokeh documentation
The code is made into the body of a function, and all of of the named objects in ``args`` are available as parameters...
Read more >
bokeh.util.deprecation.deprecated Example - Program Talk
Here are the examples of the python api bokeh.util.deprecation.deprecated taken from open source projects. By voting up you can indicate which examples are ......
Read more >
Changelog - GitHub
... Remove Explicit Marker Models - #9958 [BUG] Better warn about passing source in the CustomJSFilter args dict for 2.0 and above -...
Read more >
bokeh/CHANGELOG and bokeh Releases (Page 3) | LibHunt
#11422 [component: bokehjs] [BUG] DeserializationError when trying to ... Better warn about passing source in the CustomJSFilter args dict for 2.0 and above...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found