Opening html file that app created

Hi all,

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:

  1. take some user input
  2. create a markdown file from the input (“”)
  3. convert markdown file to html file (“deck.html”) using npx command via subprocess
  4. 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 =[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?

Any help is much appreciated!

Hi @fredzett, welcome to the community! I would recommend you change the logic of your app to do the following:

  1. Accept user input
  2. Convert the user input to markdown
  3. 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)
  4. When the user downloads the file and opens it, it will automatically open a new browser window.

Best of luck!

Thanks for your reply and your suggestion. Much appreciated!

I should have been more clear in my original post. Because, unfortunately I need the specific npx command to generate the html in the form I require.

So there is no way to achieve this over streamlit-cloud?

I am not an expert on serving websites. So what would be an alternative to host the site where I could use the above script?

Could you try following this tutorial? Invoking a Python subprocess in a deployed Streamlit app - Streamlit Docs

Thanks for your support.

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).

  1. 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.

  2. 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:
        label="Download presentation",,

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?

How can you confirm that the npx command is being run? Can you locate the file using a call to ls within the subprocess?

Apparently it is not working.

I assumed it is working, because I put the result of the npx subprocess into st.write and it did not show an error message.

But I have now run os.listdir() and the html-file is not in the directory.

I guess I will have to be looking for alternatives to streamlit-cloud.

But thanks for your suggestions and support! Much appreciated!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.