You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Streamlit Highcharts汉堡菜单不显示问题求助

解决方案

1. 显式启用Highcharts导出配置

streamlit-highcharts默认可能未开启导出菜单,需在图表配置中添加exporting选项强制启用:

import streamlit as st
from streamlit_highcharts import highcharts_chart

chart_config = {
    "title": {"text": "测试图表"},
    "series": [{"data": [1, 3, 2, 4]}],
    # 启用导出汉堡菜单
    "exporting": {
        "enabled": True,
        "buttons": {
            "contextButton": {
                "menuItems": ["downloadPNG", "downloadJPEG", "downloadPDF", "downloadSVG"]
            }
        }
    }
}

highcharts_chart(chart_config)

2. 升级streamlit_highcharts版本

你使用的streamlit_highcharts 0.2版本较陈旧,存在导出功能的兼容性bug,执行命令升级到最新稳定版:

pip install --upgrade streamlit-highcharts

3. 升级Streamlit版本

Streamlit 1.3版本过旧,与新版streamlit_highcharts可能存在前端渲染冲突,建议升级到兼容版本:

pip install --upgrade streamlit

升级后需重新测试图表功能,确认无版本冲突问题。

4. 排查浏览器环境问题

  • 确保浏览器未禁用JavaScript(导出菜单依赖JS渲染)
  • 清除浏览器缓存或使用无痕模式打开应用,排除缓存导致的渲染异常

5. 手动添加导出按钮(备选方案)

若上述方法无效,可在页面中手动添加下载按钮,通过Highcharts导出API实现:

import streamlit as st
from streamlit_highcharts import highcharts_chart
import requests

chart_config = {
    "title": {"text": "测试图表"},
    "series": [{"data": [1, 3, 2, 4]}]
}

highcharts_chart(chart_config, key="my_chart")

if st.button("下载图表为PNG"):
    export_payload = {
        "options": chart_config,
        "type": "png",
        "width": 800
    }
    response = requests.post("https://export.highcharts.com/", json=export_payload)
    if response.status_code == 200:
        st.download_button(
            label="保存PNG",
            data=response.content,
            file_name="chart.png",
            mime="image/png"
        )

内容的提问来源于stack exchange,提问作者Nicolas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 15:54:54