I have created a streamlit app which runs fine on my local machine. However, I cannot get it running on the streamlit-cloud. In a nutshell my app does the following:
take some user input
create a markdown file from the input (“deck.md”)
convert markdown file to html file (“deck.html”) using npx command via subprocess
opens a new tab showing the html file via subprocess
On my local machine I use the following command to do steps 3 and 4:
import subprocess
def markdown2marp(file):
# Create HTML
marp_it = f"npx @marp-team/marp-cli@latest --theme custom.css --html {file}"
# Open HTML in Browser
file = file.split(".")[0] # remove .md
proc = subprocess.run([marp_it], shell=True, stdout=subprocess.PIPE)
subprocess.Popen(['open', f'{file}.html'])
return proc
Now on the streamlit cloud this is not working. How can I achieve the above withouth using subprocess? Is it even possible? If so could you give me some ideas how I could achieve this?
Hi @fredzett, welcome to the community! I would recommend you change the logic of your app to do the following:
Accept user input
Convert the user input to markdown
Convert eh markdown file to HTML using a python package and offer it to be downloaded via the st.download_button() function (maybe using md-to-html · PyPI)
When the user downloads the file and opens it, it will automatically open a new browser window.
The tutorial does not solve my problem. Reason being that I do not try to run python in subprocess I guess.
Meanwhile I have concluded that running the npx command using subprocess does work.
However, the resulting html file cannot be opened using subprocess. So I tried two other options (both of which work on my local machine).
using webbrowser module to open the html file I have created. There is no error message, but the file does also not open using streamlit-cloud.
using a download button to download the html file. This results in the following error message using streamlit-cloud.
I use the following code block to download the html-file:
with open("deck.html", 'rb') as f:
st.download_button(
label="Download presentation",
data=f.read(),
file_name="deck.html",
mime='application/xhtml+xml',
)
But I do get this error message.
FileNotFoundError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you're on Streamlit Cloud, click on 'Manage app' in the lower right of your app).
Where is the file I create via my streamlit app located in the cloud?