Cannot render any Tree charts from PyEcharts in Streamlit

Hi guys,

Iā€™ve tried many options to render any PyEchartsā€™ Tree charts in Streamlit, yet no luckā€¦

https://gallery.pyecharts.org/#/Tree/README

Has anyone ever succeeded? @andfanilo maybe? :wink:

Thanks,
Charly

1 Like

Bonjour !

Donā€™t forget to remove the .render("tree_base.html") part if you are copy-pasting the code to streamlit-echarts :wink:

from pyecharts import options as opts
from pyecharts.charts import Tree
from streamlit_echarts import st_pyecharts


data = [
    {
        "children": [
            {"name": "B"},
            {
                "children": [{"children": [{"name": "I"}], "name": "E"}, {"name": "F"}],
                "name": "C",
            },
            {
                "children": [
                    {"children": [{"name": "J"}, {"name": "K"}], "name": "G"},
                    {"name": "H"},
                ],
                "name": "D",
            },
        ],
        "name": "A",
    }
]
c = (
    Tree()
    .add("", data)
    .set_global_opts(title_opts=opts.TitleOpts(title="Tree-åŸŗęœ¬ē¤ŗ例"))
)
st_pyecharts(c)

image

:raised_hand_with_fingers_splayed:
Fanilo

3 Likes

Perfect, thanks!

Next step is to convert raw JSON (or CSV) to the flare.json format.

Do you know if thereā€™s any way to do it programmatically?

Few solutions Iā€™ve just stumbled upon which Iā€™ll have to try after work! :):


Thanks,
Charly

Well that would make a great hardcore interview question for my future Python interns, thanks :smiley: yeah it looks like something youā€™re going to need to dive in after workā€¦good luck!

1 Like

Haha! I canā€™t wait to delve into this! Iā€™ll post my findings in here! :+1: