arnaudmiribel / streamlit-extras

Discover, try, install and share Streamlit re-usable bits we call "extras"!
https://extras.streamlit.app
Apache License 2.0
715 stars 123 forks source link

✨ [IDEA] - expose filename in chart_container #151

Open iuiu34 opened 1 year ago

iuiu34 commented 1 year ago

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)
arnaudmiribel commented 4 weeks ago

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