Main Content

Simple Mortgage Calculator Web App

This example shows how to create a web app and host it on the development version of 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. In the workflow, you:

  • Package the simple calculator app from App Designer using the Web App Compiler app or compiler.build.webAppArchive in MATLAB Compiler™. This step creates a web app archive (.ctf) file.

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

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

Prerequisites

  1. Install and configure the development version of MATLAB Web App Server™.

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

    setupExample("matlab/MortgageCalculatorExample",pwd)

Package and Create Web App Using Web App Compiler

  1. Start MATLAB.

  2. Type webAppCompiler at the MATLAB command line to open the Web App Compiler app.

  3. In the MAIN FILE section of the toolstrip, click the + button to add the Mortgage.mlapp file to the project. The Web App Compiler automatically resizes to include an App details section that contains information about the app such as app name, author, summary, description, and version. You can edit information about the app in App Designer by clicking Edit App Details. Click Refresh to update Web App Compiler with any changes you have made.

    • (Optional) Make sure to use a display name that is easy to distinguish when your web app is deployed to the server.

    • (Optional) Provide a version number for tracking purposes. The version number is visible on the web apps home page.

    • (Optional) Add a description for your web app in the Summary field. This description is visible on the web apps home page.

  4. In the Archive information section, specify the archive name as myMortgageWebApp.

  5. Click Package to package the app, and create a web app archive (.ctf file).

    In the Save Project dialog box that opens, specify a project name and a location where you want to save the web app project. Web App Compiler saves your project and opens a Package dialog box.

  6. Once packaging is complete, in the Package dialog box, click Open output folder. This opens the project folder, which contains the following files:

    • myMortgageWebApp.ctf

    • mccExcludedFiles.log

    • PackagingLog.html

    • requiredMCRProducts.txt

    You can view the log file, PackagingLog.html, to see the exact mcc syntax used to package and create the web app archive.

Package and Create Web App Using compiler.build.webAppArchive

Note

If you have already created a standalone application using the Web App Compiler app, you can skip this section. However, if you want to know how to create a web app from the MATLAB command window using a programmatic approach, follow these instructions.

  1. Build a web app archive 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.

  2. 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 MATLAB Compiler Limitations.

    • 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

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

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

    Operating SystemApps Folder Location

    Windows®

    %ProgramData%\MathWorks\webapps\R2024b\apps

    Linux®

    /local/MathWorks/webapps/R2024b/apps

    macOS

    /Library/Application Support/MathWorks/webapps/R2024b/apps

    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.

  3. 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

  1. To run a web app, click the myMortgageWebApp tile on the web apps home page.

    The web app opens in a new tab.

  2. 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.

    Mortgage Calculator Web App

    Mortgage calculator web app results.

Related Topics