import streamlit as st import st_hc as hct import download_chart as dc # Define the highchart definition cd2 = { "chart":{ "animation":False }, "title":{ "text":"Cartographie des parties prenantes" }, "tooltip":{ "valueDecimals":0 }, "xAxis":{ "title":{ "text":"Influence" }, "min":0, "max":100, "plotLines":[ { "color":"gray", "dashStyle":"LongDash", "width":1, "value":50, "label":{ "rotation":0, "y":290, "style":{ "color":"blue", "font-size": "20px" }, "text":"Tenir informé", }, "zIndex":3 }, { "color":"gray", "dashStyle":"LongDash", "width":1, "value":50, "label":{ "rotation":0, "y":25, "style":{ "color":"orange", "font-size": "20px" }, "text":"Gérer étroitement", }, "zIndex":3 }, { "color":"gray", "dashStyle":"LongDash", "width":1, "value":0, "label":{ "rotation":0, "y":25, "style":{ "color":"green", "font-size": "20px" }, "text":"Rendre satisfait", }, "zIndex":3 }, { "color":"gray", "dashStyle":"LongDash", "width":1, "value":0, "label":{ "rotation":0, "y":290, "style":{ "color":"red", "font-size": "20px" }, "text":"Suivre de près", }, "zIndex":3 }, { "color":"gray", "dashStyle":"LongDash", "width":1, "value":100, "zIndex":3 } ] }, "yAxis":{ "title":{ "text":"Pouvoir" }, "min":0, "max":100, "plotLines":[ { "color":"gray", "dashStyle":"LongDash", "width":1, "value":50, "zIndex":3 }, { "color":"gray", "dashStyle":"LongDash", "width":1, "value":100, "zIndex":3 }, { "color":"gray", "dashStyle":"LongDash", "width":1, "value":0, "zIndex":3 } ], }, "tooltip":{ "headerFormat":"", "pointFormat":"{point.name}", "valueDecimals":0 }, "series":[ { "type":"bubble", "maxSize":50, "cursor":"move", "name":"Influence", "pointformat":"{point.name}", "dragDrop":{ "draggableX":True, "draggableY":True, "dragMinY":0, "dragMaxY":100, "dragMinX":0, "dragMaxX":100, "dragPrecisionX":1, "dragPrecisionY":1, "dragSensitivity":0 }, "data":[], "colorByPoint":True, } ], "exporting": { "enabled": True }, "legend":{ "enabled":False } } def construct_data(): data = [] for i in range(10): object = { "x": 50+i*5, "y": 50, "name": f"Point{i}", } data.append(object) return data def test_chart(): #The component can render any highchart definition if len(st.session_state['pp_grouped']) == 0: return None points = st.session_state['pp_grouped'] cd2["series"][0]["data"] = points chart = hct.streamlit_highcharts(cd2,640) #640 is the chart height # if chart: # st.session_state['pp_grouped'] = chart st.write(chart) if st.session_state['save']: st.session_state['save'] = False st.session_state['pp_grouped'] = chart.copy() emp = st.empty() col0, col1, col2, col3 = st.columns([1,1,1,1]) if col1.button("Sauvegarder"): st.session_state['pp_grouped'] = chart.copy() emp.success("Saved") st.experimental_rerun() if col2.button("Télécharger"): if not chart: st.error("Un truc ne va pas. Veuillez réessayer") else: st.session_state['pp_grouped'] = chart.copy() fig = dc.construct_plot() st.plotly_chart(fig)