Streamlit ECharts

0.6.0 · active · verified Thu Apr 16

Streamlit ECharts is a Streamlit component that enables the display of highly interactive ECharts visualizations directly within Streamlit applications. The library is actively maintained, with its latest version being 0.6.0, and has a cadence of several major releases per year, often introducing significant updates and breaking changes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to render a basic ECharts bar chart using `st_echarts`. It also shows how to use the `key` parameter for stable component identity and `on_select='rerun'` for basic interactivity, capturing selection events in the Streamlit app state. An optional commented section illustrates usage with PyEcharts, which requires an extra installation.

import streamlit as st
from streamlit_echarts import st_echarts
import json # For PyEcharts conversion
# import pyecharts.options as opts # Optional: if using pyecharts
# from pyecharts.charts import Bar # Optional: if using pyecharts

st.set_page_config(layout='wide')
st.title('Streamlit ECharts Basic Bar Chart')

# ECharts option as a Python dictionary
options = {
    'xAxis': {
        'type': 'category',
        'data': ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    'yAxis': {
        'type': 'value'
    },
    'series': [{
        'data': [820, 932, 901, 934, 1290, 1330, 1320],
        'type': 'bar'
    }]
}

st.header('Basic ECharts Bar Chart')
result = st_echarts(
    options=options,
    height='400px',
    key='basic_bar_chart', # Essential for stable animations/interactions
    on_select='rerun' # Example: trigger rerun on selection
)

if result and result.get('selection'):
    st.write(f"Selected data point: {result['selection']}")

# Example with PyEcharts (requires `pip install streamlit-echarts[pyecharts]`)
# if st.checkbox("Show PyEcharts Example (requires pyecharts extra)"):
#     b = (
#         Bar()
#         .add_xaxis(["Microsoft", "Amazon", "IBM", "Oracle", "Google"])
#         .add_yaxis("2018 Revenue (billion $)", [21.2, 20.4, 10.3, 6.08, 4])
#         .set_global_opts(
#             title_opts=opts.TitleOpts(title="Top Cloud Providers", subtitle="2018 Revenue")
#         )
#     )
#     st.header('PyEcharts Bar Chart (via st_pyecharts)')
#     st_pyecharts(b, height="400px", key='pyecharts_chart')

view raw JSON →