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

Dataframe toolbar download button does not work when Streamlit app is iframed cross-origin #8528

Open
3 of 4 tasks
sfc-gh-jkinkead opened this issue Apr 18, 2024 · 3 comments
Assignees
Labels
feature:st.data_editor feature:st.dataframe priority:P2 status:confirmed Bug has been confirmed by the Streamlit team type:bug Something isn't working

Comments

@sfc-gh-jkinkead
Copy link
Contributor

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

When a Streamlit app is hosted in an iframe in a different origin than the parent frame, the download button in the dataframe toolbar silently fails with a console error.

This is arguably a bug in the native-file-system-adapter library used by this widget.

It's a little surprising that this has very different behavior from st.download_button.

Reproducible Code Example

// Run this snippet with node.
// If saved in `server.js`, run with `node server.js`.
const http = require("http");

const requestListener = function (req, res) {
    res.setHeader("Content-Type", "text/html");
    res.setHeader("Content-Security-Policy", "frame-src http://localhost:3000;");
    res.writeHead(200);
    res.end('<html><body><h1>App below:</h1><iframe sandbox="allow-popups allow-same-origin allow-scripts allow-downloads" src="http://localhost:3000" /></body></html>');
};

const host = "localhost";
const port = 3001;
const server = http.createServer(requestListener);
server.listen(port, host, () => {
    console.log(`Server is running on http://${host}:${port}`);
});

# Run as a Streamlit on port 3000.
# If saved in a file `repro.py`, run with `streamlit run repro.py`.
import streamlit as st
import pandas as pd

ratings_df = pd.DataFrame(
    [
        {"command": "st.selectbox", "rating": 4, "is_widget": True},
        {"command": "st.balloons", "rating": 5, "is_widget": False},
        {"command": "st.time_input", "rating": 3, "is_widget": True},
    ]
)
st.dataframe(ratings_df, use_container_width=True)

Steps To Reproduce

  1. Run the Streamlit app above.
  2. Run the node server above, which iframes the Streamlit app cross-origin.
  3. Open the node server in chrome (localhost:3001).
  4. Hover over the dataframe table.
  5. Click the "download" icon.

Expected Behavior

The CSV downloads in some way (in the background, in a new tab, via a file picker).

Current Behavior

Nothing happens.

The following is printed in the console:
image

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version: develop; 1.31.1; 1.29.0
  • Python version: N/A
  • Operating System: OS X
  • Browser: Chrome

Additional Information

No response

@sfc-gh-jkinkead sfc-gh-jkinkead added type:bug Something isn't working status:needs-triage Has not been triaged by the Streamlit team labels Apr 18, 2024
Copy link

If this issue affects you, please react with a 👍 (thumbs up emoji) to the initial post.

Your feedback helps us prioritize which bugs to investigate and address first.

Visits

@SarthakNikhal
Copy link

@sfc-gh-jkinkead Can I work on this issue?

@sfc-gh-jkinkead
Copy link
Contributor Author

@SarthakNikhal - This is a duplicate of #8210 ; I didn't find it when searching.

@LukasMasuch has a draft patch up #8452 , so would be better to coordinate with.

@LukasMasuch LukasMasuch added feature:st.dataframe feature:st.data_editor status:confirmed Bug has been confirmed by the Streamlit team priority:P2 and removed status:needs-triage Has not been triaged by the Streamlit team labels Apr 18, 2024
@LukasMasuch LukasMasuch self-assigned this Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:st.data_editor feature:st.dataframe priority:P2 status:confirmed Bug has been confirmed by the Streamlit team type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants