Main Content

Simple Mortgage Calculator Web App

This example shows how to create a web app and host it on the MATLAB® Web App Server™. The example uses the simple calculator app from App Designer as a basis for the web app. For information about the app and the numerical values you can enter, see Plot Numeric Data in an App (MATLAB). In the workflow, you:

  • Use the compiler.build.webAppArchive function in MATLAB Compiler™ to package a simple mortage calculator app created using MATLAB® App Designer. This step creates a web app archive (.ctf) file.

  • Deploy the web app archive (.ctf) file to the MATLAB Web App Server.

  • Run the web app from the web apps home page.

MathWorks® has two offerings of MATLAB Web App Server:

  • A standalone MATLAB® Web App Server™ product.

  • A development version of MATLAB Web App Server included in MATLAB Compiler™.

For details, see MATLAB Web App Server Differences.

Note: This example uses the development version of MATLAB Web App Server included in MATLAB Compiler to deploy the web app. However, the web app can also be deployed to the MATLAB Web App Server product.

Prerequisites

Install MATLAB Web App Server and set up the server.

Development Version of MATLAB Web App Server (MATLAB Compiler)

MATLAB® Web App Server™ Product

Download the MATLAB app file Mortgage.mlapp to your current working directory by executing:

setupExample("matlab/MortgageCalculatorExample",pwd)

Create Web App Using compiler.build.webAppArchive

Build a web app archive from the MATLAB app using the compiler.build.webAppArchive command. Use name-value arguments to specify the archive name.

buildResults = compiler.build.webAppArchive('Mortgage.mlapp',...
    'ArchiveName','myMortgageWebApp');

The compiler.build.Results object buildResults contains information on the build type, generated files, and build options.

The build function generates the following files within a folder named myMortgageWebAppwebAppArchive in your current working directory:

  • mccExcludedFiles.log — Log file that contains a list of any toolbox functions that were not included in the web app. For more information on non-supported functions, see Limitations (MATLAB Compiler).

  • myMortgageWebApp.ctf — Component technology file that contains the deployable archive.

  • requiredMCRProducts.txt — Text file that contains product IDs of products required by MATLAB Runtime to run the web app.

  • unresolvedSymbols.txt — Text file that contains information on unresolved symbols.

Deploy Web App

Navigate to the project folder generated by MATLAB Compiler during the packaging process.

Copy the web app archive file myMortgageWebApp.ctf to the apps folder configured by the server. The default location is:

Windows

%ProgramData%\MathWorks\webapps\<release>\apps

Linux

/local/MathWorks/webapps/<release>/apps

macOS

/Library/Application Support/MathWorks/webapps/<release>/apps

Note: Replace <release> with your MATLAB release. For example, R2023b.

You can also open the apps folder by clicking the Open App Folder button in the server application. For more information, see Start the Server Application.

Click the Open Home Page button in the server application. This action opens the web apps home page using your default web browser. You see a tile displaying the simple mortgage calculator web app. Your web app is now deployed.

Run Web App

To run a web app, click the myMortgageWebApp tile on the web apps home page. The web app opens in a new tab.

Click the Monthly Payment button to get the monthly payment and the principal and interest graph.

You have successfully created, deployed, and run a web app.

See Also

| |