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: