Update a Markup widget

Hi all,

I am fairly new to Bokeh, a complete novice when it comes to Javascript and HTML, but fairly experienced with Python.

What I am trying to do is create a Bokeh dashboard. That dashboard includes both plots and also text that is updated regularly.

Obviously with the plots there is no problem, I am making use of ColumnDataSources to update my data and everything is working really well.

However I can’t work out how to update the text in a Div widget. To be clear, it is not meant to be updated in response to a user interaction, rather I have a python loop that continuously “streams” new data that to display.

My apologies if this is really obvious to some, but I have spent a lot of time searching for this now and can’t seem to work out the answer. I thought maybe something could be done with a CustomJS callback but I am not sure how to get it to trigger, or how to pass data to it from python for that matter.

Thank you

You can write a callback for the ColumnDataSource that you use to plot your data like below.

from bokeh.io import show

from bokeh.models import ColumnDataSource, CustomJS, Div

from bokeh.layouts import gridplot

from bokeh.plotting import figure

TOOLS = ‘tap’

fig = figure(tools=TOOLS)

source = ColumnDataSource(data={‘x’:range(10),‘y’:range(10)})

fig.scatter(x=‘x’,y=‘y’,size=20,source=source)

txt = Div(text=‘Text will be updated with current time anytime anything happens to the ColumnDataSource’)

source_code = “”"

var time = new Date()

txt.text = time.getHours() + “:” + time.getMinutes() + “:” + time.getSeconds();

“”"

source.callback = CustomJS(args={‘txt’:txt},code=source_code)

grid = gridplot([[fig,txt]],toolbar_location=None)

show(grid)

``

Here the text is updated anytime something happens to the data (it can only be clicked on in the example), but you could have it updated under certain conditions only.

hi
you peoples are know very much about python can you tell how to read external text file in python or anaconda i am using codes but i didn’t any result tell me solution as early as possible.

Thanking you,

···

On Tue, Jul 25, 2017 at 8:12 AM, Sébastien Roche [email protected] wrote:

You can write a callback for the ColumnDataSource that you use to plot your data like below.

from bokeh.io import show

from bokeh.models import ColumnDataSource, CustomJS, Div

from bokeh.layouts import gridplot

from bokeh.plotting import figure

TOOLS = ‘tap’

fig = figure(tools=TOOLS)

source = ColumnDataSource(data={‘x’:range(10),‘y’:range(10)})

fig.scatter(x=‘x’,y=‘y’,size=20,source=source)

txt = Div(text=‘Text will be updated with current time anytime anything happens to the ColumnDataSource’)

source_code = “”"

var time = new Date()

txt.text = time.getHours() + “:” + time.getMinutes() + “:” + time.getSeconds();

“”"

source.callback = CustomJS(args={‘txt’:txt},code=source_code)

grid = gridplot([[fig,txt]],toolbar_location=None)

show(grid)

``

Here the text is updated anytime something happens to the data (it can only be clicked on in the example), but you could have it updated under certain conditions only.

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/58041e8b-6708-4bdc-a326-798ae8cb435d%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi,

This question is off-topic for this mailing list, which is created to help with support for the Bokeh visulization library. For general python programming advice or help, you might try Stack Overflow:

  https://stackoverflow.com/

Or a python community mailing list:

  Mailing Lists | Python.org

Thanks,

Bryan

···

On Jul 24, 2017, at 23:28, leela vathi <[email protected]> wrote:

hi
             you peoples are know very much about python can you tell how to read external text file in python or anaconda i am using codes but i didn't any result tell me solution as early as possible.
                  Thanking you,

On Tue, Jul 25, 2017 at 8:12 AM, Sébastien Roche <[email protected]> wrote:
You can write a callback for the ColumnDataSource that you use to plot your data like below.

from bokeh.io import show
from bokeh.models import ColumnDataSource, CustomJS, Div
from bokeh.layouts import gridplot
from bokeh.plotting import figure

TOOLS = 'tap'

fig = figure(tools=TOOLS)

source = ColumnDataSource(data={'x':range(10),'y':range(10)})

fig.scatter(x='x',y='y',size=20,source=source)

txt = Div(text='Text will be updated with current time anytime anything happens to the ColumnDataSource')

source_code = """
var time = new Date()

txt.text = time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds();
"""

source.callback = CustomJS(args={'txt':txt},code=source_code)

grid = gridplot([[fig,txt]],toolbar_location=None)

show(grid)

Here the text is updated anytime something happens to the data (it can only be clicked on in the example), but you could have it updated under certain conditions only.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/58041e8b-6708-4bdc-a326-798ae8cb435d%40continuum.io\.

For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAA0r%2BooYu-QQJ_ucVkyr__voMWb9WNZv7vBTn5BALjZF6AM36Q%40mail.gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.