Engineers often rely on Python scripts to solve or verify the result of complex computational problems. However, sharing and collaborating on these scripts can be challenging, and they may not always be user-friendly because not everyone is good at coding. CalcTree offers a solution enabling you to convert your Python scripts into web applications, making them more accessible and shareable. This article will show you how to transform your Python script into a web app using CalcTree.
What is CalcTree
CalcTree, is a calculation management platform. You can sign-up and build hosted, shareable web apps (complete with an API and a web publishing module) with tools like Python and Spreadsheets. Learn more here!
Structuring Your Python Script for a Web App
Before converting your Python script into a web app, it's essential to structure the problem into inputs and outputs. This will help you understand how your app will receive input from the user, transfer the input to Python code for computation, and finally transfer the calculation output back to the page for the user.
Here's an example of how you might structure the input and output for a Python script that designs a baseplate according to EC3.
Page parameter input
ULS design load,
NEd
Steel strength,
fyk
Concrete strength,
fck
Steel section properties e.g.
b,h,tf
Page parameter output
Bearing capacity,
fjd
Required base plate width,
wp
Required base plate width,
lp
Required base plate thickness,
tp
Now, let's explore the three basic steps to convert your Python script into a web app using CalcTree.
Step 1: Add Necessary Input Parameters to the Page Content
First, add the necessary input parameters to the page content. This will allow users to input the required data for your Python script to compute. Follow these steps:
Type / on the page to receive the command menu
Click on the Parameter field or press Enter to insert a parameter on the page. Change the default Untitled title of the parameter to an appropriate symbol.
Here's an example of what the input parameters might look like for the base plate design:
Inputs
Base plate
Ned
:20.0kN
fy
:275MPa
Concrete Support Properties
fck
:25MPa
acc
:0.85
yc
:1.50
Steel Column Properties
Section
:IPE - 500
h
:500mm
b
:200mm
r
:21.00
tw
:10.20mm
tf
:16mm
Perimeter
:1,744.00mm
Area
:11,552.00mm2
Step 2: Add Your Python Code
Next, add a Python source to your page. Follow these steps:
Go to the Integrations panel on the right sidebar and click the "+ Add" button.
Click the "Code" button to add your Python source.
Write or paste your Python code inside the code editor, in the window at the bottom of your page.
Here's an example of what the code might look like for the base plate design:
👉 Note all the input page parameters are accessed by Python using "_page_" prefix, e.g. _page_b , _page_h, _page_tf. You can just type the name of your page parameter in the code editor, and a suggestion box will identify and allow you to select your parameters on the page.
Step 3: Add Calculated Python Parameters to Page Content
Your output parameters will appear on the right-hand side of your screen, in the page parameter list under Code source. To add these to your page, you can simply click and drag them to the page.
This will display the results of your Python code on the page for the user to see.
Here's an example of how you might arrange the output parameters for for the base plate design:
Outputs
fjd
:14.24MPa
Areq
:351,185mm2
c
:146mm
lp
:792mm
Wp
:492mm
tp
:58mm
Output parameters of a base plate with an I-section
Is the calculator valid, that is, do the T-stubs overlap?
check
:OK, there is no overlap between T-stubs.
👉 Note each output parameter is a block on the page, which can be grabbed and moved around the page, just like other page elements.
The app is ready to be published, see the live base plate designer in the link below:
CalcTree is a powerful platform that enables engineers to convert their Python scripts into user-friendly web applications. By following the three basic steps outlined in this article, you can transform your Python script into a web app, making it easier to share and collaborate with your colleagues.