Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to download data from Streamlit #400

Open
anhhd opened this issue Oct 14, 2019 · 15 comments
Open

Ability to download data from Streamlit #400

anhhd opened this issue Oct 14, 2019 · 15 comments
Labels

Comments

@anhhd
Copy link

@anhhd anhhd commented Oct 14, 2019

[Edited by tvst, since we narrowed the focus of this feature request]

I'd love to be able to:

  • ingest data - csv file, etc - I see this is already being worked on.
  • do stuff with it - easy with streamlit, as users can tweak stuff till they get the results they are happy with.
  • present csv/excel file of the final (with results added) data for download - I can save this to the server using pandas for example but not sure how to present it nicely for the user to download within the streamlit app itself. It would be nice to have a streamlit widget thingamajig.

Implementation suggestion: The existing streamlit object which displays stuff on screen could have a download option for objects like dataframes. So st.write(data) or just st.dataframe(data) should have a download button somewhere.

Sort of how some of the plotting tools in python like plotly displays a download button for charts.

@anhhd anhhd added the enhancement label Oct 14, 2019
@markopy

This comment has been minimized.

Copy link

@markopy markopy commented Oct 15, 2019

The upload part of this is being tracked under #120

@khalido

This comment has been minimized.

Copy link

@khalido khalido commented Oct 17, 2019

Is the download part being worked on to?

I'd love to be able to:

  1. ingest data - csv file, etc - I see this is already being worked on.
  2. do stuff with it - easy with streamlit, as users can tweak stuff till they get the results they are happy with.
  3. present csv/excel file of the final (with results added) data for download - I can save this to the server using pandas for example but not sure how to present it nicely for the user to download within the streamlit app itself. It would be nice to have a streamlit widget thingamajig.

Implementation suggestion: The existing streamlit object which displays stuff on screen could have a download option for objects like dataframes. So st.write(data) or just st.dataframe(data) should have a download button somewhere.

Sort of how some of the plotting tools in python like plotly displays a download button for charts.

@tvst

This comment has been minimized.

Copy link
Collaborator

@tvst tvst commented Oct 24, 2019

Since "upload" is already covered by #120 (which is currently in progress!) I'll change this issue to track the download case.

@tvst tvst changed the title Upload & Download button Ability to download data from Streamlit Oct 24, 2019
@tconkling

This comment has been minimized.

Copy link
Contributor

@tconkling tconkling commented Oct 30, 2019

As a temporary workaround, you can patch streamlit.lib.Server.TORNADO_SETTINGS to add a "static_path" entry that points to a folder you want to serve static files from.

I made a gist here: https://gist.github.com/tconkling/1e5ead87c796a82de7fa71fcc4a74777

@MarcSkovMadsen

This comment has been minimized.

Copy link

@MarcSkovMadsen MarcSkovMadsen commented Nov 1, 2019

An alternative to @tconkling that I've been using for my prototype behind a firewall is just to run a seperate, simple fileserver before I run streamlit.

python -m  http.server 8502 --directory /app/storage/ &
streamlit run app.py

You can change the port (8502) and directory (/app/storage/) to something that suits you.

@monchier

This comment has been minimized.

Copy link
Contributor

@monchier monchier commented Nov 13, 2019

Please, see here for more info about the TORNADO_SETTINGS hack.

Another option that adds an explicit route to a static file: https://gist.github.com/monchier/b3c200a002f8030db07fa72f8827f10f

Still, in the realm of short term solutions, I like @MarcSkovMadsen file server solution better. Similarly, this can be done very efficiently with a proxy like Nginx. See some docs here.

@MarcSkovMadsen

This comment has been minimized.

Copy link

@MarcSkovMadsen MarcSkovMadsen commented Dec 4, 2019

Hi All

I’ve discovered a workaround for downloading small files from streamlit.

I’ve added it to the gallery at awesome-streamlit.org. It’s called “File Download Workaround”. You can try it out and copy the code.

file_download_workaround

@artem-konevskikh

This comment has been minimized.

Copy link

@artem-konevskikh artem-konevskikh commented Dec 12, 2019

Hi Marc!
Thanks for nice workaround. BTW You can add download attribute to a tag to define proper filename to avoid saving via right-click menu. Like this:

href = f'<a href="data:file/csv;base64,{b64}" download="{filename}.csv">Download CSV File</a>'

@quinn-dougherty

This comment has been minimized.

Copy link

@quinn-dougherty quinn-dougherty commented Jan 29, 2020

I think csv download would be ideal as a part of st.dataframe. i would really love to see a button in the top right of the dataframe display, for instance, that downloads csv.

@cedias

This comment has been minimized.

Copy link

@cedias cedias commented Feb 19, 2020

Hey,
another simple use case for that download feature:

  • generating a plotly offline graph standalone html file and being able to download it seamlessly !
@vijaysaimutyala

This comment has been minimized.

Copy link

@vijaysaimutyala vijaysaimutyala commented Mar 4, 2020

I was implementing @tconkling gist and the download was enabled. However I see this issue loading css chunk failed. The app is supposed to display a dataframe where it fails. I assumed thi was bcz, since we're using a folder named static to download the files and the css also being pointed to static, it was somehow not able to look at the css it intended to. So instead of static in the server.py, I gave it another name and it still shows the same issue.

However if I remove the patch, I dont see this issue anymore !

image

@vijaysaimutyala

This comment has been minimized.

Copy link

@vijaysaimutyala vijaysaimutyala commented Mar 4, 2020

Looks like I messed up. While the server is running, I updated the config/server.py file which might have caused the issues. I've closed the server and redid everything and it worked.

@vijaysaimutyala

This comment has been minimized.

Copy link

@vijaysaimutyala vijaysaimutyala commented Mar 4, 2020

Sorry for the multiple comments though. But the app randomly shows a blank page with the fix in tornado setting in Server.py for file download.

@bballamudi

This comment has been minimized.

Copy link

@bballamudi bballamudi commented Mar 23, 2020

An alternative to @tconkling that I've been using for my prototype behind a firewall is just to run a seperate, simple fileserver before I run streamlit.

python -m  http.server 8502 --directory /app/storage/ &
streamlit run app.py

You can change the port (8502) and directory (/app/storage/) to something that suits you.

This is a cool hack @MarcSkovMadsen . But do you know if I deploy the app in AWS and access it from a local laptop will the file be downloaded in the local laptop or in the AWS file system?

@bballamudi

This comment has been minimized.

Copy link

@bballamudi bballamudi commented Mar 23, 2020

Sorry for the multiple comments though. But the app randomly shows a blank page with the fix in tornado setting in Server.py for file download.

@vijaysaimutyala I tried @MarcSkovMadsen 's solution and it works for me when you host the app in the local computer. Yet to test if I can proceed to deploy the app in AWS and can still download the files in my local computer by accessing the app hosted in AWS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.