with one click
echarts-streamlit-sync
// Transform ECharts example URLs into Streamlit st_echarts components. Use when a user provides an ECharts editor URL and wants to add or update it as a demo in the streamlit-echarts-demo project.
// Transform ECharts example URLs into Streamlit st_echarts components. Use when a user provides an ECharts editor URL and wants to add or update it as a demo in the streamlit-echarts-demo project.
| name | echarts-streamlit-sync |
| description | Transform ECharts example URLs into Streamlit st_echarts components. Use when a user provides an ECharts editor URL and wants to add or update it as a demo in the streamlit-echarts-demo project. |
Extracts ECharts examples and transforms them into Python code for streamlit-echarts.
../echarts-examples../echarts-examples/public/examples/ts/<example-id>.tshttps://echarts.apache.org/examples/en/editor.html?c=<example-id> → file <example-id>.tstitle, category, titleCN, difficultyOnly if local source is unavailable. Navigate to the editor URL and extract the option object.
Given a URL like ?c=pie-padAngle, read ../echarts-examples/public/examples/ts/pie-padAngle.ts.
From the category in the source comment, determine target: demo_echarts/<category>.py.
Existing categories and their files:
bar, boxplot, calendar, candlestick, dataset, events, extensions,
funnel, gauge, graph, heatmap, line, map, parallel, pictorial_bar,
pie, radar, sankey, scatter, sunburst, themeriver, tree, treemap
If the category doesn't have a file yet, create a new demo_echarts/<category>.py and register it in demo_echarts/__init__.py (add to both the imports and ST_DEMOS_BY_CATEGORY).
Apply the js-echarts-to-streamlit skill rules. Key reminders:
true/false/null → True/False/NoneJsCode("...").js_codegrid, tooltip, etc.series as dict or list matching the originaldef render_<descriptive_name>():
options = { ... }
st_echarts(options=options, height="500px")
render_ + snake_case description derived from the example500px standard, 700px only for exceptionally dense chartsJsCode only if the function uses itstreamlit as st only if using session_state/st.button/st.rerunAdd entry to ST_<CATEGORY>_DEMOS dict at bottom of the file:
ST_PIE_DEMOS = {
...,
"Chart Title from Source": (
render_function_name,
"https://echarts.apache.org/examples/en/editor.html?c=example-id",
),
}
title from the source file comment block(render_function, url_string)When asked to check an existing conversion:
For examples using myChart.on('click', ...) with setOption for drill-down:
st.session_state to track current view stateevents param to capture clicks: events = {"click": "function(params) { return ... }"}result.chart_event to update state and st.rerun()st.button("Back") instead of graphic onclick handlersuniversalTransition (doesn't work across Streamlit reruns)key= param on st_echarts for stateful chartsWhen adding a category that doesn't exist yet:
demo_echarts/<category>.py with render function + ST_<CATEGORY>_DEMOS dictdemo_echarts/__init__.py:
from .<category> import ST_<CATEGORY>_DEMOS"Display Name": ST_<CATEGORY>_DEMOS to ST_DEMOS_BY_CATEGORY