Hello,
I’m working on an application to display dynamically created flowcharts based on user input. The user selects a certain process from around 100 options. The app then references a database and builds a graphviz Digraph to render a diagram of the process. These diagrams vary from 2 elements to over 50, which makes the diagram size vary widely.
I’m trying to find a solution that always displays the diagram at its native size and allows the user to scroll vertically and horizontally if necessary. I’m able to display the smaller diagrams with st.image(), but for larger diagrams, it shrinks down the size to where it isn’t readable. I also tried st.graphviz_chart(), but it cuts off parts of the image for the larger diagrams.
I also tried using st.markdown with the following code:
dot = graphviz.Digraph() #build graphviz Digraph
dot.render('static/graph', format='png', cleanup=True) #save as file in static folder
html_string = f'<a href="app/static/graph.png" target="_blank"><img src="app/static/graph.png" caption="legend"></a>'
st.markdown(html_string, unsafe_allow_html=True) #show image with HTML
This solution displays the diagram exactly as I want. However, if the user selects a different input to generate a new diagram, the app serves the old diagram. I believe either streamlit or the browser is caching the files in “app/static”. I found that if I gave the diagram image a new name each time, it worked, but then I ended up with a lot of old diagram files in the static folder, which would need to be periodically deleted.
Does anyone have any suggestions to stop the app from caching the files in static? Or does anyone have a different approach to display the varying-sized diagram images?
Thanks