1) Either install Streamlit directly or using the D-Tale extra:
pip install streamlit
pip install dtale[streamlit]
2) Invoke your Streamlit script using the dtale-streamlit
command instead of the streamlit
command:
dtale-streamlit run my_streamlit_script.py
import pandas as pd
from dtale.views import startup
df = pd.DataFrame([1, 2, 3, 4])
startup(data_id="1", data=df)
from dtale.app import get_instance
# remember we set the data_id of our previous dataframe was "1"
df = get_instance("1").data
This will allow you to gain access to any dataframe you've passed to D-Tale (assuming you've remembered the data_id
)
<iframe src="/dtale/main/1" />
This will display the standard D-Tale grid which you can perform any D-Tale operation on.
<a href="/dtale/main/1" target="_blank">Dataframe 1</a>
Here's a demo of a couple ways to use D-Tale within Streamlit
And here's the source code of the two examples in that clip:
Hope this leads to lots of new ideas of how Flask can be used within Streamlit! Please support open-source by putting your ⭐ on this repo!