streamlit-extras
streamlit-extras copied to clipboard
✨ [IDEA] - expose filename in chart_container
Description
Would be nice to be able to customize the download filename in chart_container. So that,
chart_container(data`, filename="test")
downloads files "test.csv", "test.parquet" instead of always "data.csv", "data.parquet".
This is only about exposing "data" arg in line 88 as an argument of the class.
Minimal code for the extra
def chart_container(
data: pd.DataFrame,
tabs: Sequence[str] = (
"Chart 📈",
"Dataframe 📄",
"Export 📁",
),
export_formats: Sequence[str] = _SUPPORTED_EXPORT_KEYS,
filename: str
) -> Generator:
(...)
with tab_3:
st.caption("Export limited to 1 million rows.")
export_data = data.head(1_000_000)
for chosen_export_format in export_formats:
export_utils = _SUPPORTED_EXPORTS[chosen_export_format]
exporter = export_utils["function"]
extension = export_utils["extension"]
st.download_button(
f"Download data as {extension}",
data=exporter(export_data),
file_name=filename + extension,
mime=export_utils.get("mime"),
key=_get_random_widget_key(),
)
Screenshots

Hey @iuiu34, good idea. Feel free to drop a PR for this if you still need it!