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.

[FEATURE] Allow named columns to be used in EditTools

See original GitHub issue

In the examples below I will be using the LineEditTool developed in feature branch #9968

However I believe that the issue/feature I will describe applies generally to all the EditTools and could potentially be implemented on the abstract base class.

My problem is that there appears to be only two methods of successfully getting an edit tool to work.

1) passing in data directly to the p.line method as arguments as shown in the example below

from datetime import datetime, timedelta
from bokeh.models import ColumnDataSource, LineEditTool, Circle
from bokeh.plotting import figure
from bokeh.io import curdoc, show


p = figure(
    y_range=(0, 10),
    x_axis_type="datetime",
    width=400,
    height=400,
    title="TimeSeries Edit Tool",
)

dates = [datetime(2020, 5, 1) + timedelta(days=x) for x in [1, 2, 3, 4, 5, 6, 7, 8, 9]]
l1 = p.line(
    dates,
    [1, 2, 3, 4, 5, 4, 3, 2, 1],
    color="green",
    alpha=1.0,
    line_width=5,
)

c1 = p.circle([], [], size=10, color="red")
ledit_tool = LineEditTool(renderers=[l1], intersection_renderer=c1, dimensions="height")
p.add_tools(ledit_tool)

curdoc().add_root(p)
show(p)

2) creating CDS where the columns MUST be named x and y or else the edit tool does not function.

from datetime import datetime, timedelta
from bokeh.models import ColumnDataSource, LineEditTool, Circle
from bokeh.plotting import figure
from bokeh.io import curdoc, show


p = figure(
    y_range=(0, 10),
    x_axis_type="datetime",
    width=400,
    height=400,
    title="TimeSeries Edit Tool",
)

dates = [datetime(2020, 5, 1) + timedelta(days=x) for x in [1, 2, 3, 4, 5, 6, 7, 8, 9]]
cds = ColumnDataSource({"x": dates, "y":[1, 2, 3, 4, 5, 4, 3, 2, 1]})
l1 = p.line(
    x="x",
    y="y",
    source=cds,
    color="green",
    alpha=1.0,
    line_width=5,
)

c1 = p.circle([], [], size=10, color="red")
ledit_tool = LineEditTool(renderers=[l1], intersection_renderer=c1, dimensions="height")
p.add_tools(ledit_tool)

curdoc().add_root(p)
show(p)

Looking at the doc strings for the edit tools it seems like the necessity of using x and y is known.

The tool will modify the columns on the data source corresponding to the 
``x`` and ``y`` values of the glyph. Any additional columns in the data
source will be padded with the declared``empty_value``, when adding a new
point.

I would think that generally when people are making complex interactive dashboards they will be using the CDS option and it is highly likely they are going to want to be using their own names for the columns rather than forced to use x and y so that the edit tools work.

This is certainly true in my case. While I have gotten my code to work using the x and y restriction, it did force changes that made the code less readable and generally worse off.

3) Proposed 3rd option where CDS with custom named columns can be used

I think a 3rd option would be useful where the CDS can be used and the edit tool takes additional keyword arguments allow the names of the columns to be passed.

If this can be implemented on the EditTool base class it may not be a large change but could end up having quite a large effect.

Below is the code below that I would like to see working but currently does not.

from datetime import datetime, timedelta
from bokeh.models import ColumnDataSource, LineEditTool, Circle
from bokeh.plotting import figure
from bokeh.io import curdoc, show


p = figure(
    y_range=(0, 10),
    x_axis_type="datetime",
    width=400,
    height=400,
    title="TimeSeries Edit Tool",
)

dates = [datetime(2020, 5, 1) + timedelta(days=x) for x in [1, 2, 3, 4, 5, 6, 7, 8, 9]]
cds = ColumnDataSource({"datetime": dates, "prediction":[1, 2, 3, 4, 5, 4, 3, 2, 1]})
l1 = p.line(
    x="datetime",
    y="prediction",
    source=cds,
    color="green",
    alpha=1.0,
    line_width=5,
)

c1 = p.circle([], [], size=10, color="red")
ledit_tool = LineEditTool(x="datetime", y="prediction", renderers=[l1],
        intersection_renderer=c1, dimensions="height")
p.add_tools(ledit_tool)

curdoc().add_root(p)
show(p)

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
scaine1commented, May 20, 2020

Ahhh! that’s what that part of the code was for 😃 Not surprising the issue was caused by code I wrote and my lack of bokeh knowledge.

Yep I will fix and make a PR.

0reactions
scaine1commented, May 23, 2020

Sorry I was quite confused. I wasn’t quite aware that the changes were already in the master branch. For some reason I thought they were still kept on a seperate branch as part of the bokeh repository.

I pulled down the latest master and added just my bug fix.

Thanks for your patience and guidance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring plot tools — Bokeh 2.4.3 Documentation
Sometimes, especially with stacked charts, it is desirable to allow the name of the column to be specified indirectly. In this case, use...
Read more >
Editing Tools - NCBI - NIH
Use the scroll bar on the right to scroll down to see all rows. Tools Select All Rows. Clicking on the name of...
Read more >
Edit a list column - Microsoft Support
You can change list column settings, such as the column's name and type. Depending on the type of column, you can also make...
Read more >
Modify Features tool reference—ArcGIS Pro | Documentation
The Modify Features pane contains tools that edit finished features. When you enable map topology, tools that move, reshape, or edit vertices include...
Read more >
DataEditR
Rows or columns can be added to the data from within the data editor by ... To use this feature, the options for...
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