python - 如何在 Streamlit 上运行 Bokeh 服务器
问题描述
我想在 Streamlit 上显示一个交互式散景图,但我无法在图中添加小部件。带有 show(p) 命令的绘图显示在选项卡上,但我无法显示小部件。Bokeh serve show 命令完美运行,但我如何在 Streamlit 中使用它。
import pandas as pd
import streamlit as st
from bokeh.models import ColumnDataSource, Select
from bokeh.plotting import figure,ColumnDataSource, show
from bokeh.models import FactorRange
from bokeh.models import NumeralTickFormatter
from math import radians
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, Grid, LinearAxis, Plot, VBar
from bokeh.io import curdoc, show
from bokeh.models import HoverTool
from bokeh.models.widgets import Slider
from bokeh.layouts import column, row
import streamlit
st.title("Hello world!")
uploaded_file = st.file_uploader("Choose a file")
if uploaded_file is not None:
df = pd.read_excel(uploaded_file)
df = pd.read_excel("C:/Users/Files/Data.xls")
df1 = df.groupby(['A','B'])['C'].sum().reset_index()
#st.write(df1)
df2 = df1.sort_values(by=['B'], ascending=False)
st.write(df2)
data_source = ColumnDataSource(df2)
x = 10
range = FactorRange(factors=list(df2.iloc[:x]['A'].unique()))
p = figure(x_range = range ,plot_height=600,title="Top Spend by
Vendors",toolbar_location=None, plot_width=1200)
r = p.vbar(x='A', top='B', width=0.04, color ='red', source=data_source)
p.yaxis.formatter=NumeralTickFormatter(format="$0,0")
p.xaxis.major_label_orientation=radians(60)
def update_plot(attr, old, new):
label = "Siddharth"
v_custom = streamlit.slider(label,10,30,5, step=1)
st.write('Values:', v_custom)
range = FactorRange(factors=list(df2.iloc[:v_custom]['Supplier'].unique()))
Currnew = ColumnDataSource(df2[['A', 'B']])
p.x_range.factors = list(df_filter1['Vendor'].unique())
r.data_source.data = Currnew.data
v_custom.on_change('value', update_plot)
解决方案
在 streamlit 中使用时散景 2.0 损坏。使用早期版本在streamlit中使用bokeh
推荐阅读
- regex - 当我使用 BeautifulSoup 中的 findAll 和正则表达式(re.compile)在 python 中进行网络抓取时,我无法使用 css 类正确循环它
- python - 如何在python中用“'”替换“\\u0027”?
- xamarin - 在为 Google Play 构建 Xamarin Forms 应用程序时,是否需要在 ABI 上生成更多内容?
- angularjs - 更新控制器内的范围变量时,$scope.$watch 太慢了
- c# - 为什么我会收到此错误: System.UnauthorizedAccessException: 'C:\Windows\system32\CSV_file'
- sql - oracle DB SQL上的特殊字符
- java - 遍历二维数组并将值放入映射
- javascript - 如何在 Electron 桌面应用程序中管理表单提交?
- google-apps-script - 如何在 Google Script 中创建图表并将其作为图像保存到 Google Drive
- vba - 在 powerpoint 中创建插入图的位置