Main Content

Deploy Graph Database Application with MATLAB Compiler

This example shows how to write a script to analyze data stored in a graph database, and deploy the script as a standalone application. Write code that connects to the Neo4j® database, imports data from the database into MATLAB®, analyzes the data, and closes the database connection. Then, you can deploy the code by compiling it as a standalone application by using the Application Compiler (MATLAB Compiler) app and running the application on other machines.

Overall, the example follows the steps described in Create Standalone Application from MATLAB Function (MATLAB Compiler) and updates the steps for a standalone database application.

Ensure that you have administrator privileges on the other machines to run the standalone application.

Create Function in MATLAB

Write a MATLAB script named findShortestPathBetweenPeople.m and save it in a file location of your choice. The script contains the findShortestPathBetweenPeople function, which returns the distance between two people in a graph network. The function performs these actions:

  • Connects to a Neo4j database running on the local machine

  • Imports graph data and converts it to a directed graph

  • Performs the shortest path analysis

  • Closes the database connection

type findShortestPathBetweenPeople.m
function distance = findShortestPathBetweenPeople(userA,userB)

%  FINDSHORTESTPATHBETWEENPEOPLE The findShortestPathBetweenPeople function
%  connects to a Neo4j® database, imports data from the database into
%  MATLAB®, finds the shortest path between two people, and closes the
%  database connection.

%%
% Create a Neo4j connection object |neo4jconn| using the URL
% |http://localhost:7474/db/data|, user name |neo4j|, and password
% |matlab|.

url = 'http://localhost:7474/db/data';
username = 'neo4j';
password = 'matlab';

neo4jconn = neo4j(url,username,password);

%%
% Find all the |Person| nodes and all the relationships associated with
% each |Person| node using |searchGraph|.

social_graphdata = searchGraph(neo4jconn,{'Person'});

%%
% Using the table |social_graphdata.Nodes|, access the |name| property for
% each node that appears in the |NodeData| variable of the table.
%
% Assign the table |social_graphdata.Nodes| to |nodestable|.

nodestable = social_graphdata.Nodes;

%%
% Assign the row names for each row in the table |nodestable| to
% |rownames|.

rownames = nodestable.Properties.RowNames;

%%
% Access the |NodeData| variable from |nodestable| for each row. |nodedata|
% contains an array of structures.

nodedata = [nodestable.NodeData{rownames}];

%%
% To retrieve the |name| field from each structure, index into the array.
% |nodenames| is a cell array of character vectors that contains node names.

nodenames = {nodedata(:).name};

%%
% Create the |digraph| object |social_graph| using the
% |neo4jStruct2Digraph| function with the graph data stored in
% |social_graphdata| and the node names stored in |nodenames|.

social_graph = neo4jStruct2Digraph(social_graphdata,'NodeNames',nodenames);

%%
% Find the shortest path between |UserA| and |UserB| using |shortestpath|.

[~,distance] = shortestpath(social_graph,userA,userB);

%%
% Close the database connection.
close(neo4jconn)

Create Standalone Application Using Application Compiler App

On the MATLAB Apps tab, on the far right of the Apps section, click the arrow to open the apps gallery. Under Application Deployment, click Application Compiler.

In the MATLAB Compiler project window, specify the main file of the MATLAB application that you want to deploy.

  1. In the Main File section of the toolstrip, click .

  2. In the Add Files dialog box, browse to the file location that contains your saved script. Select findShortestPathBetweenPeople.m and click Open. The Application Compiler app adds the findShortestPathBetweenPeople function to the list of main files.

Decide whether to include the MATLAB Runtime installer in the generated application by selecting one of the two options in the Packaging Options section:

  • Runtime downloaded from web — Generates an installer that downloads the MATLAB Runtime and installs it along with the deployed MATLAB application

  • Runtime included in package — Generates an installer that includes the MATLAB Runtime installer

Customize the packaged application and its appearance by entering the following options:

  • Application information — Editable information about the deployed application. You can also customize the appearance of the standalone application by changing the application icon and splash screen. The generated installer uses this information to populate the installed application metadata.

  • Additional installer options — Options for editing the default installation path for the generated installer and selecting a custom logo.

  • Files required for your application to run — Additional files required by the generated application to run. The software includes these files in the generated application installer.

  • Files installed for your end user — Files that are installed with your application. These files include the generated readme.txt file and the generated executable for the target platform.

  • Additional runtime settings — Platform-specific options for controlling the generated executable.

For details about these options, see Customize an Application (MATLAB Compiler).

To generate the packaged application, click Package in the Package section on the toolstrip. In the Save Project dialog box, specify the location in which to save the project.

In the Package dialog box, verify that Open output folder when process completes is selected.

When the deployment process is complete, examine the generated output.

  • for_redistribution — Folder containing the file that installs the application and the MATLAB Runtime.

  • for_testing — Folder containing all the artifacts created by mcc (such as binary, header, and source files for a specific target). Use these files to test the installation.

  • for_redistribution_files_only — Folder containing the files required for redistributing the application. Distribute these files to users who have MATLAB or MATLAB Runtime installed on their machines.

  • PackagingLog.txt — Log file generated by MATLAB Compiler™.

Install and Run Standalone Application

To install the standalone application, in the for_redistribution folder, double-click the MyAppInstaller_web executable.

If you want to connect to the Internet using a proxy server, click Connection Settings. Enter the proxy server settings in the provided dialog box. Click OK.

To complete the installation, follow the instructions in the installation wizard.

To run your standalone application:

  1. Open a terminal window.

  2. Navigate to the folder in which you installed the application.

  3. Run the application.

Test Standalone Application on Target Machine

Choose one target machine to test the MATLAB generated standalone application.

Copy the files in the for_testing folder to the target machine.

To test your standalone application:

  1. Open a terminal window.

  2. Navigate to the for_testing folder.

  3. Run the application.

Deploy Standalone Application on Target Machines

Copy the for_redistribution_files_only folder to a file location on all target machines where MATLAB or MATLAB Runtime is installed and the Neo4j database server is running.

Run the MATLAB generated standalone application on all target machines by using the executable in the for_redistribution_files_only folder.

See Also

| | |

Related Topics