Deploy a Web App to Convert Batch or Fed-Batch Model to Flow Models (PFR/CSTRs)
Overview
This web app was designed to enable users to upload a batch or fed-batch Dynochem model and convert this model to a continuous model (PFR, 1 tank CSTR, or 3 tank CSTR model). In addition, the user may simulate their batch or continuous models via RunScript Automation before finally downloading a new continuous model based on the chemistry in the batch model. This web app is designed to be deployable across your organization or used locally. The code could be used ‘as-is’ or serve as an inspiration for further development and customization. Deploying this web app (or like web app) across your organization can save users time and enable users gain further use of reaction models.
Getting Started
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.27.2)
- plotly (we used 5.14.1)
- pandas (we used 2.0.3)
In this illustration we use a technology called Streamlit to create the front-end and run Dynochem using Python code. Using Streamlit, no front-end development in Javascript, HTML or CSS are needed. For simple deployments, Streamlit also bypasses the need for web server software (like Apache or IIS). This web app leverages much of the code previously developed to quickly generate a web app from a Dynochem model Dynochem.py
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. 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 all files (including Dynochem.py, sus_sessionstate.py, Batch to Flow Introduct.py) and subfolders (pages,temp_files, template_model).
- Access the ‘server’ machine where the model will run (e.g. using Remote Desktop)
- Make a folder on the server machine and save the downloaded script files and subfolders in that folder
-
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 Batch_to_Flow_Introduction.py
or, to lauch on a specific server port:
streamlit run Batch_to_Flow_Introduction.py --server.port XX
- This web app is a multi-page streamlit app, and with the command above, the app will open on the ‘Batch to Flow Introduction’ page.
- Proceed to the page called ‘1. Upload Batch Model’ and drag or browse to a Dynochem batch or fed-batch reaction model. Here is an example model if needed:example DC model.
- A simulation of the batch model for the first scenario will appear.
- Test that the editting the number inputs 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.
Instructions for how to use the web app
- This web app will launch on the ‘Batch to Flow Introduction’ page with the intructions above. Read the Introduction and notes on model stipulations before proceeding. In addition, it is recommend to have all Excel instances close on the server
- Proceed to the page called ‘1. Upload Batch Model’ and drag or browse to a Dynochem batch or fed-batch reaction model. Note, if starting from a Reaction Lab model, the Reaction Model should first be exported to a Dynochem model (in Excel) using the export feature in Reaction Lab (Excel icon in Reaction Lab or go to File>Export>Excel in Reaction Lab)
- A simulation of the batch model for the first scenario will appear. Other scenarios may be selected from a droplist at the top of the page. In addition, the initial conditions as listed on the scenarios sheet of the model may be editted using the number inputs in the sidebar. Changes made on this page will be carried into the conversion to a flow model.
- Click on any of the pages for the flow models, including ‘PFR (tube)’, ‘CSTR (1 tank)’, or ‘CSTR (3 tanks)’. In the background, the web app script will convert the components, reactions, and relevant initial conditions into a template flow model. A new simulation of this flow model will appear. Edits may be made using the number inputs in the sidebar. Note, some parameters were given default values that are design choices for the user to edit further.
- Explore the simualtion plots, reactor Information and results.
- Once the user is satisfied with the simulation, the model may be downloaded by clicking the ‘Create File for Download’. A link will appear just below the button that will allow a new Dynochem file (.xlsx) to be downloaded in the browser.
- This new model file may then be applied or editted for further use in Dynochem for process design and optimization.
Third party References and Resources
- Streamlit : https://www.streamlit.io/
- Python : https://www.python.org/
- pywin32 : https://pypi.org/project/pywin32/