Обновление графика с помощью ползунка с python и боке - PullRequest
0 голосов
/ 09 мая 2020

Здравствуйте, люди из интеллекта rnet,

Итак, я попытался сделать простую интерактивную визуализацию, в которой я могу использовать ползунок, чтобы изменить радиус некоторых точек на графике, используя python и боке. . Однако, когда я пытаюсь выполнить функцию обновления, мне кажется, что я получаю сообщение об ошибке: 500: Internal Server Error.

Я также пытался сделать функцию обновления так, чтобы она делала бессмысленную переменную, но ошибка сообщение все равно появится и не покажет ни сюжета, ни слайдера.

Итак, мой вопрос: как я могу сделать слайдер, который будет изменять радиус круга с помощью сервера боке?

# 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()

Заранее спасибо!

1 Ответ

0 голосов
/ 09 мая 2020

Уже исправил, вот код

# 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()
...