iT邦幫忙

1

Python Bokeh繪製表,使用menu,能否連動?

  • 分享至 

  • xImage

您好:

參考如本範例如下:
請問,其中MENU,不能連動,是正常的嗎?
謝謝

https://ithelp.ithome.com.tw/upload/images/20250112/20104095sAZn5al2Vr.png

from bokeh.plotting import figure, output_file, show
from bokeh.models import CategoricalColorMapper
from bokeh.plotting import ColumnDataSource
from bokeh.layouts import column, row
from bokeh.models.widgets import Dropdown
import pandas as pd

df = pd.read_csv("iris.csv")
output_file("Ch15_4_2b.html")

c_map = CategoricalColorMapper(
        factors=["setosa","virginica","versicolor"],
        palette=["blue","green","red"]
        )

data = ColumnDataSource(data={
        "x": df["sepal_length"],
        "y": df["sepal_width"],
        "x1": df["petal_length"],
        "y1": df["petal_width"],
        "target": df["target"]
        })

p1 = figure(title="鳶尾花資料集-花萼")
p1.circle(x="x", y="y", source=data, size=15,
         color={"field": "target", "transform": c_map}, 
         legend_label="target")

p2 = figure(title="鳶尾花資料集-花瓣")
p2.circle(x="x1", y="y1", source=data, size=15,
         color={"field": "target", "transform": c_map}, 
         legend_label="target")

#建立下拉選單的元件
menu = [("setosa","1"),("virginica","2"),("versicolor","3")]
#建立下拉選單
mnu = Dropdown(label="鳶尾花種類", menu=menu)

layout = column(mnu, row(p1, p2))
show(layout)
froce iT邦大師 1 級 ‧ 2025-01-13 12:57:52 檢舉
1. 要互動的話要run server
https://docs.bokeh.org/en/2.4.3/docs/user_guide/server.html

2. demo
https://demo.bokeh.org/weather
https://github.com/bokeh/bokeh/blob/main/examples/server/app/weather/main.py

自己看city_select.on_change()這句的用法
city_select.on_change('value', update_plot)
noway iT邦研究生 1 級 ‧ 2025-01-16 19:51:28 檢舉
您好:
我往書後面看
有教 bokeh server --show Ch15_6_2.py
他可以獨立讓一個py互動

那請問,一般建立好多個 xx.py,是要放在哪一種SERVER
後續可以類似網站哪樣點選連結,即進到 xx.py 執行互動?
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答