forked from andfanilo/streamlit-echarts-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
71 lines (60 loc) · 2.52 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import inspect
import textwrap
import streamlit as st
from demo_echarts import ST_DEMOS
from demo_pyecharts import ST_PY_DEMOS
def main():
st.title("Streamlit ECharts Demo")
with st.sidebar:
st.header("Configuration")
api_options = ("echarts", "pyecharts")
selected_api = st.selectbox(
label="Choose your preferred API:",
options=api_options,
)
page_options = (
list(ST_PY_DEMOS.keys())
if selected_api == "pyecharts"
else list(ST_DEMOS.keys())
)
selected_page = st.selectbox(
label="Choose an example",
options=page_options,
)
demo, url = (
ST_DEMOS[selected_page]
if selected_api == "echarts"
else ST_PY_DEMOS[selected_page]
)
if selected_api == "echarts":
st.caption(
"""ECharts demos are extracted from https://echarts.apache.org/examples/en/index.html,
by copying/formattting the 'option' json object into st_echarts.
Definitely check the echarts example page, convert the JSON specs to Python Dicts and you should get a nice viz."""
)
if selected_api == "pyecharts":
st.caption(
"""Pyecharts demos are extracted from https://github.com/pyecharts/pyecharts-gallery,
by copying the pyecharts object into st_pyecharts.
Pyecharts is still using ECharts 4 underneath, which is why the theming between st_echarts and st_pyecharts is different."""
)
demo()
sourcelines, _ = inspect.getsourcelines(demo)
with st.expander("Source Code"):
st.code(textwrap.dedent("".join(sourcelines[1:])))
st.markdown(f"Credit: {url}")
if __name__ == "__main__":
st.set_page_config(
page_title="Streamlit ECharts Demo", page_icon=":chart_with_upwards_trend:"
)
main()
with st.sidebar:
st.markdown("---")
st.markdown(
'<h6>Made in  <img src="https://streamlit.io/images/brand/streamlit-mark-color.png" alt="Streamlit logo" height="16">  by <a href="https://twitter.com/andfanilo">@andfanilo</a></h6>',
unsafe_allow_html=True,
)
st.markdown(
'<div style="margin-top: 0.75em;"><a href="https://www.buymeacoffee.com/andfanilo" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a></div>',
unsafe_allow_html=True,
)