streamlit-extras icon indicating copy to clipboard operation
streamlit-extras copied to clipboard

✨ [IDEA] - expose filename in chart_container

Open iuiu34 opened this issue 1 year ago • 1 comments

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

![DESCRIPTION](LINK.png)

iuiu34 avatar Jul 10 '23 08:07 iuiu34

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

arnaudmiribel avatar Jul 31 '24 12:07 arnaudmiribel