altair - 使用 VConcat 在 Streamlit 中未显示 Altair 图表
问题描述
我尝试使用 streamlit 投影 altair 图表。我的要求是以这样的方式投影两个图表,如果我在上面的图表中选择几个带有分散点的点,我应该在下面的图表中看到变量('notes')的分布。为此,我编写了以下代码,我在函数中使用了 vconcat。但是,当我使用 vconcat 时,图表永远不会出现。但是,当我尝试投影单个图表时它工作正常。
def altair_graph(embd_1):
selected = alt.selection_single(on="click", empty="none")
brush = alt.selection(type='interval')
dom = ['Other IDs', 'Slected ID','Sel Dims']
rng_clr = ['lightgrey', 'red','blue']
color_point=alt.Color('color', scale=alt.Scale(domain=dom, range=rng_clr))
color = alt.condition(selected, alt.value('red'), color_point,legend=None)
chart = alt.Chart(embd_1).mark_circle(size=30).encode(
x = 'dimention1:Q',
y = 'dimention2:Q',
tooltip=['ID','notes'] ,
color=color
).properties(width=600,height=600).add_selection(brush).add_selection(selected).interactive()
bars = alt.Chart(embd_1).mark_bar().encode(
y='notes:N',
color='notes:N',
x='count(notes):Q'
).transform_filter(brush).interactive()
#final_chart = ((chart & bars))
final_chart = alt.vconcat(chart,bars)
return final_chart
selected=altair_component(altair_chart=altair_graph(embd_1))
解决方案
从您的代码片段中,我假设您正在使用streamlit-vega-lite自定义组件的 altair-part。目前似乎无法使用 streamlit-vega-lite 组件从复合图表中检索选择。
也就是说,我并不完全清楚为什么图表根本没有显示。如果没有最小的可重现示例,我们将无法进行测试。我最近遇到了一个类似的案例,它可以单独绘制图表,也可以将图表组合在一起。选择也可以这样工作,但是,值不会反映在从altair_component
推荐阅读
- amazon-web-services - ALB/Lambda 和目标组的配置问题
- distributed-system - 当每次写入都不需要 fsync 时,raft 如何实现强一致性
- string - 如何从一行中删除某些单词,但将其余部分放入带有批处理的字符串/变量中?
- python - Matplotlib,为学术论文绘制灰色图
- c++ - 无法在 C++ 中删除动态对象
- discord.js - 收集结束时的消息
- docker - Docker Registry 存储未更新
- sql - 如何在表中找到没有反向顺序对的对?
- react-native - redux saga 的延迟功能不起作用
- javascript - 将日期字符串更改为季节