Create and deploy a web app based on your model
A free GitHub account is required to access the program code in this repository; send us your GitHub username.
- Install Python and the scaleup library using instructions and options we provide here
- Install the following additional Python modules using pip in a DOS window (pip install module-name):
- streamlit (we used 1.20.0)
- plotly (we used 5.13.1)
- xmltodict (we used 0.13.0)
Creating a web app extends access to your model across your organization, to colleagues who may not be Scale-up Suite users (yet) and to users on devices such as phones and tablets.
In this illustration we use a technology called Streamlit to create the front-end and run Dynochem and Reaction Lab models using Python code. Using Streamlit and the example files Dynochem(.py) or Reactionlab(.py) together, no front-end development in Javascript, HTML or CSS are needed; the standard user interface is generated automatically from the scenarios tab in your model. For simple deployments, Streamlit also bypasses the need for web server software (like Apache or IIS).
A free GitHub account is required to access the program code in this repository; send us your username to access Dynochem.py and Reactionlab.py. By design, users can deploy any model in a standard manner without writing or changing a single line of this code or any part of their working DC model. For simple deployments, no special server software is needed.
RunScript Automation is required to run the code in this repository. This product is available with Scale-up Suite 2, which includes Dynochem 6 and Reaction Lab 2. Contact your Scale-up Systems representative if you would like to obtain licenses for this new product, which are currently part of our Digitalization Pilot Program. See this KB article for basic details on Dynochem automation and this one for information specific to RunScript Automation.
How to use the code and deploy any model as a web app [allow 5 minutes]
- Download and save the appropriate Python script, Dynochem.py and/or Reactionlab.py
- Access the ‘server’ machine where the model will run (e.g. using Remote Desktop) (one-time machine machine set-up details are given below)
- Make a folder on the server machine and save your working model and the script in that folder; there should only be one model file in the folder; if needed, here is an example DC model; and an example RxL model
-
Open a DOS window in that folder (type ‘cmd’ in the address bar; better options below) and type the following at the DOS prompt:
streamlit run scriptname --server.port XX
where scriptname is either Dynochem.py or Reactionlab.py depending on the type of model and XX is the ‘port’ (or link address) that will be dedicated for users of this web app; standard choices are 8501 and higher. The app will open immediately on the server (e.g. in the default browser; modern browsers like Chrome, Safari, Firefox work well).
- Test that the slider bars are doing what you expect and that the model runs and plots results
- Share the address of the app with end users as Machine address (or name):XX.
That’s it. You’re done.
See a live version
A live web app for a simple model and demo purposes is often running here.
How to start the web app service using a script
You can use a DOS batch file to run the streamlit command, instead of opening a DOS window, e.g.
cd C:\Users\<userid>\Automation\Model1\
streamlit run Dynochem.py --server.port 8506
where the path in the first line points to the folder containing the Dynochem.py file and the Dynochem model you want to use.
You can also run a series of the above batch files in another batch file. Streamlit may also be run from Powershell and in Powershell scripts instead of batch files.
Setting up the server to run the web app [one time only; IT task]
You can deploy a web app locally for access by your colleagues and using your own computer as the ‘server’. This is easy and quick but not suitable for a permanent stable deployment supporting many users. This section describes deploying to a server and is oriented towards people with IT skills and is a one time only set-up, in case you do not already have a suitable server machine on which to run the simulations. You need a computer with the same basic software and hardware requirements as any Scale-up Suite install. It is common to use a Windows server machine (e.g. Windows server 2012 or later). It is also common for that to be a ‘cloud’ machine, provided by Amazon (AWS) or Microsoft (Azure). If you are reading this, you probably have many of those already.
- Install Scale-up Suite and sign in to enable access to a (RunScript Automation) license from your pool when required:
- We recommend you authenticate using an API Key you will receive or have generated as part of your App Deployment License; see here for further details
- On some Windows Server setups, you may be prompted to install .NET 4.8; if so, use this link
- Install Python using instructions and options we provide here
- Install the following additional Python modules using pip in a DOS window (pip install module-name):
- plotly
- streamlit
- xmltodict
The app will now work locally. Some additional network security settings may be required to ensure that the necessary ports on the server machine are open for users of the web app, see example settings below.
To test your installation locally:
- Create a test folder to hold a sample model
- Copy or download Dynochem.py or Reactionlab.py to the test folder
- Copy or download a sample model to the test folder
- Open a DOS or Powershell command window
-
Go to the test folder and execute the following command:
streamlit run Dynochem.py --server.port 8080
or
streamlit run Reactionlab.py --server.port 8080
- If this is the first time you are running streamlit, then you will get a ‘Welcome to Streamlit!’ message along with a prompt to enter an e-mail address. You can ignore this and simply press enter
-
You will now see the following message:
You can now view your Streamlit app in your browser. Local URL: http://localhost:8080 Network URL: http://10.0.1.5:8080
-
A browser window will open and, after a few seconds, display the results of running the chosen model:
If a browser window does not open, simply open the browser and use either of the URLs reported by Streamlit
Note that Streamlit does not support Internet Explorer (IE) 11 or earlier versions so if you are running this on Windows Server 2012R2 or later, you will need to download an alternative browser such as Chrome.
To deploy securely behind IIS, please see instructions here.
Originally Developed and Tested on
The python code was developed and tested on this set-up:
- Amazon EC2 t2-medium
- Windows Server 2012
- Scale-up Suite 2
- Python 3.7.3 (32 bit)
- Python 3.7 pywin32-224
- Streamlit 0.62.1 (with 32 bit Python)*
- Google Chrome
- Inbound ports (TCP 8501-8510) open in Windows and AWS (AWS source: 0.0.0.0/0 and ::/0)
The deployment procedure has been tested on the following systems:
- Amazon EC2 (t2-small and t2-medium instances)
- Windows Server 2012R2 (64 bit)
- Scale-up Suite 2
- Python 3.8.5 (32 bit)
- Python 3.8 pywin32-228
- Streamlit 0.62.1 (with 32 bit Python)
- Google Chrome 84.0.4147.135 (64 bit)
- Inbound ports (TCP 8501-8509)
- Microsoft Office not installed
- Microsoft AzureVM (Standard B2s instance)
- Windows Server 2019
- Scale-up Suite 2
- Python 3.8.5 (32 bit and 64 bit)
- Python 3.8 pywin32-228
- Streamlit 0.65.1 (with 64 bit Python)
- Streamlit 0.62.1 (with 32 bit Python)
- Google Chrome 84.0.4147.135 (64 bit)
- Inbound ports (TCP 8081-8089)
- Microsoft Office not installed
Restrictions
- Streamlit does not support Internet Explorer (IE) 11 or earlier versions.
Known Issues
- 14 October 2020 - There are known issues with PythonWin and Python 3.9 that affect the win32ui. These may prevent the use of the above Web App toolkit with Python 3.9.
- 19 February 2020 - Versions of the xlrd package greater than 2.0 only support XLS files. Version 1.2.0 is explicitly required to read XLSX files.
Third party References and Resources
- Streamlit : https://www.streamlit.io/
- Python : https://www.python.org/
- pywin32 : https://pypi.org/project/pywin32/