-
Notifications
You must be signed in to change notification settings - Fork 262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Update Bokeh plots from PyComponent #684
Comments
Alternatively, I guess I would like to know if there is a way to replace the entire |
Ah!, I found a hackish way to do it from flexx import flx
import numpy as np
from bokeh.plotting import figure
from flexx import app, ui
from bokeh.models import ColumnDataSource
from bokeh.embed import components
x = np.linspace(0, 6, 50)
data={'x': x, 'y': np.sin(x)}
source = ColumnDataSource(data)
p1 = figure(tools="pan,wheel_zoom,box_zoom,reset")
p1.toolbar.logo = None
p1.line(x='x', y='y', source=source)
p1.sizing_mode = 'scale_height'
class Example(app.PyComponent):
def init(self):
with ui.VSplit():
self.plot = ui.BokehWidget.from_plot(p1)
self.freq = flx.Slider(title='Frequency', max=2.0, value=1.0)
@flx.reaction
def update_plot(self):
new_dict = {'x': x, 'y': np.sin(self.freq.value * x)}
source.data = new_dict
script, div = components(p1)
script = '\n'.join(script.strip().split('\n')[1:-1])
self.plot.set_plot_components(
dict(script=script, div=div, id=self.plot.id))
if __name__ == '__main__':
app = flx.App(Example)
m = app.launch('chrome-browser') # for use during development
flx.run() |
Yeah, I'm not sure if there is a way for Flexx to detect changes to |
You can create a separate JS component that updates the data source of the plot.
ds.data is your datasource
For your example above
Hope this helps |
Hi,
I am new to flexx, but really like it. In the bokeh-example, a line plot is updated using JS code.
However, one of the strenghts of bokeh is that we can do numpy calculations and update
the plots dynamically from Python. Is this possible in flexx?
For instance, this does not work:
Even though
source.data
is updated successfully, the plot does not update as it would using just bokeh.Is there any simple way to get around this?
The text was updated successfully, but these errors were encountered: