Setup Test

Warning

When you first open the repository in VSCode, you may be asked if you want to reopen the folder in a container.

Ignore this message and close the prompt.

The container is just provided for those who will need a web-based backup for running the exercises - more guidance will be given during the HSMA session.

If you would prefer to watch this guide in video form, please see the video embedded below:

Install the environment

  1. Open the Anaconda Prompt

  2. Navigate to the folder you’ve stored the environment folder in using the cd (change directory) command.

cd C:\HSMA\h6_7b_web_apps_1\environment
  1. Install the environment from the yml file
conda env create -f environment.yml

If you receive an error about exceeding the maximum number of retries or having a SSL error, try editing the environment.yml file to replace ‘conda-forge’ with ‘defaults’.

Before

After

Save the file and try again.

If the environment has partially installed before reaching this failure point, it may tell you that you cannot install the environment due to the prefix already existing. If this is the case, run the following command:

conda env remove -n hsma_webdev

Then you can rerun the conda env create -f environment.yml command.

Run a sample streamlit app

Selecting the hsma_webdev environment

First, we need to make sure we’ve selected the correct environment.

Click into the python file test_streamlit_app.py and select the hsma_webdev environment from the dropdown that appears.

Tip

Alternatively, to access the interpreter/environment select from any file within VSCode, click CTRL + SHIFT + P and choose ‘Python: Select Interpreter’ from the dropdown list that appears.

You may need to start typing ‘interpreter’ to get it to show up.

Running the app in the terminal

Next, open up a terminal.

Warning

If you had a terminal open when you selected the hsma_webdev environment, this terminal may not have updated to be pointing towards this new environment - though in recent versions of VSCode it appears this behaviour may have changed!

Take a look before the start of the filepath - this should indicate the environment you have selected.

If this doesn’t work

  • First try opening an additional terminal with the plus button

  • If this doesn’t work and you are using a powershell terminal, click on the dropdown arrow next to the plus sign and open a ‘command prompt’ (cmd) terminal instead.

  • If neither of these work, try running conda activate hsma_webdev

or

In your powershell or cmd terminal, run the command

streamlit run test_streamlit_app.py

Note

You may receive a popup telling you that you need to allow Python through the firewall. Click ‘allow’ if you are able to.

If your IT department blocks this, you can either - ask them to allow it - use the alternative web-based option we will provide for the Streamlit sessions

If the app runs successfully, you should see a message like the below in the terminal.

A browser window will either open separately or within your VSCode.

If it doesn’t open up, navigate to the ‘Local URL’ shown. CTRL + Click on the link in the terminal should open it up, or you can type in the address in your preferred web browser.

The web app should look like this:

or like this

depending on whether your OS preferences are set to ‘dark mode’.

Closing the app

Closing down VSCode will shut the app down.

Alternatively, while you still have the browser window with the app open, press CTRL + C to close down the app server.

Warning

If you try to close the app in this way while the browser window is shut, it will fail to close. However, you can just kill the terminal manually with the rubbish bin icon.