Deploy quantstats graphs

I want to deploy the graphs of the quantstats library in my app, and it has not been possible, I have tried with st.write, st.components.v1.html, etc. Here is a couple of code that I have made:

import quantstats as qs

stock = qs.utils.download_returns(‘FB’)

fig = qs.plots.snapshot(stock, title=‘Facebook Performance’)

st.write (fig)

Any help

I’m not sure, but you can try qs.to_plotly(fig) and then use st.plotly_chart to show it

1 Like

didn’t work

Can you confirm in, say Jupyter notebook, that the figure you create comes up with outside of Streamlit? ( won’t render in Streamlit so it’s not a helpful line inside of a Streamlit app.)

Also, in Streamlit, if you do st.write(type(fig)), what do you get? I did a quick peek at the library and it looks like it’s using Matplotlib, so if you can confirm the type of figure you have, you might try st.pyplot(fig) to show a Matplotlib figure. (I tried st.write(fig) with a Matplotlib figure and it worked fine for me, so not sure there.)

It may be helpful to confirm what version everything is on (Streamlit, quantstats, Matplotlib [or whatever library is underneath this quantstats figure]).

Did you run below code ok?

import quantstats as qs

stock = qs.utils.download_returns('FB')

I can’t run it and found: Example doesn't work · Issue #236 · ranaroussi/quantstats · GitHub

1 Like

when I use st.write(type(fig)) it returns <class ‘NoneType’>

I think the issue may be as @phamxtien suggested: I think there may be an issue with quantstats not generating the figure. Can you try to plot something else? I’d recommend trying out quantstats in a jupyter notebook if you continue to have trouble rendering in Streamlit so you can verify you are getting valid output from quanstats.