[使用带有python和bokeh的滑块更新图形

问题描述 投票:0回答:1

互联网的大家好,

因此,我尝试进行简单的交互式可视化,在其中可以使用滑动条使用python和bokeh更改绘图上某些点的半径。但是,当我尝试进行更新功能时,似乎收到一条错误消息,内容为:500:内部服务器错误。

我还试图使更新函数使其无意义的变量,但错误消息仍会出现,并且不显示图或滑块。

所以我的问题是:如何制作一个使用bokeh服务器改变圆弧半径的滑块?

# imports
from bokeh.io import push_notebook, show, output_notebook
from bokeh.server.server import Server
from bokeh.application import Application
from bokeh.application.handlers.function import FunctionHandler
from bokeh.layouts import column
from bokeh.models import Slider
from bokeh.plotting import figure



output_notebook()

# Webpage function, this function will be called upon creating the webpage
def make_page(doc):
    #source = ColumnDataSource(data=dict(radius=20))

    size=20

    def update(attr, old, new):
        s = new
        radius = s
        size.data = dict(radius)

    plot = figure(plot_width=400, plot_height=400)
    plot.circle([1,2], [4,8], size = size, color='blue', alpha=0.5);

    slider = Slider(start=0, end=30, value=20, step=1, title="Number")

    slider.on_change(update)
    # adding the slider and plot to the document shown on the webpage 
    # all elements of the webpage have to be added below
    doc.add_root(column(slider, plot))

# creating the application and running the server local, (http://localhost:5000), port 5000 can be changed
apps = {'/': Application(FunctionHandler(make_page))}
server = Server(apps, port=5000)
server.start()

提前感谢!

python bokeh
1个回答
0
投票

已经修复,这是代码

# imports
from bokeh.io import push_notebook, show, output_notebook
from bokeh.server.server import Server
from bokeh.application import Application
from bokeh.application.handlers.function import FunctionHandler
from bokeh.layouts import column
from bokeh.models import Slider
from bokeh.plotting import figure
from bokeh.plotting import ColumnDataSource


output_notebook()

# Webpage function, this function will be called upon creating the webpage
def make_page(doc):
    #source = ColumnDataSource(data=dict(radius=20))

    data = dict(
        x=[1,2],
        y=[4,8],
        radius=[20,20]

    )


    source = ColumnDataSource(data=data)



    def update(attr, old, new):
        radius = new
        new_data = dict(
            x=[1,2],
            y=[4,8],
            radius=[radius,radius]
        )
        source.data= new_data

    plot = figure(plot_width=400, plot_height=400)
    plot.circle(x='x', y='y', size = 'radius', color='blue', alpha=0.5, source=source);

    slider = Slider(start=0, end=30, value=20, step=1, title="Number")

    slider.on_change('value', update)
    # adding the slider and plot to the document shown on the webpage 
    # all elements of the webpage have to be added below
    doc.add_root(column(slider, plot))

# creating the application and running the server local, (http://localhost:5000), port 5000 can be changed
apps = {'/': Application(FunctionHandler(make_page))}
server = Server(apps, port=5000)
server.start()
© www.soinside.com 2019 - 2024. All rights reserved.