This example demonstrates how to add resource files such as images, CSS files, JavaScript files, and HTML files to your web application component and reference them in a WebVI without needing to upload these files to a web server.
You can also use resource files to augment the WebVI’s capabilities. For example, you can add other HTML widgets or scripts and reference them in the HTML view of the WebVI.
IncorporateUserResources/IncorporateUserResources.gwebproject
.WebApp.gcomp
and open index.gviweb
.WebApp.gcomp
to open the web application component.You can manually the move the build output found at \IncorporateUserResources\Builds
to any web server. This project also includes a Distribution (WebApp.lvdist
) that can be used to build a package (.nipkg). Packages utilize NI Package Manager to automated the process of installing, upgrading, or removing the web app. A package is also a requirement for hosting a Web application on SystemLink Cloud.
The following steps can be used to host the web app on SystemLink Cloud
IncorporateUserResources.gwebproject
.WebApp.lvdist
.The following steps can be used to host the web app on a local web server
IncorporateUserResources.gwebproject
WebApp.lvdist
.http://localhost:9090/incorporateuserresources/
C:\Program Files (x86)\National Instruments\Shared\NI WebServer\www
.WebApp_Default Web Server
directory into the www
directory.http://localhost:8080/WebApp_Default%20Web%20Server/
C:\Program Files\National Instruments\Shared\Web Server\htdocs
.WebApp_Default Web Server
directory into the htdocs
directory.http://localhost:9090/WebApp_Default%20Web%20Server/
.This example uses one type of resource: an image file.
An image is included in the images
namespace within WebApp.gcomp
. The image is a screenshot of the diagram code and is named WebVIDiagram.png
.
Refer to the following sections to learn how to add resource files to a web application component and reference them in a WebVI.
WebApp.gcomp
to open the web application component.styles
folder for CSS files or an images
folder for image files.You can reference a resource file using its relative URL. The relative URL is determined by the namespace of the WebVI and the namespace of the resource file.
Examples:
WebApp/index.gviweb
WebApp/myImage.jpg
myImage.jpg
WebApp/ChildNamespace1/index.gviweb
WebApp/ChildNamespace2/myImage.jpg
../ChildNamespace2/myImage.jpg
my image.jpg
should be my%20image.jpg
.Edit panel HTML
button in the toolbar to launch the HTML source dialog.Add the following line in between the <head></head>
tags:
<link rel="stylesheet" type="text/css" href="[your-stylesheet].css">
Example:
<head>
<!-- ... other head content ... -->
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
Edit panel HTML
button in the toolbar to launch the HTML source dialog.Add the following line in between the <head></head>
tags:
<script src="[your-script].js" type="text/javascript"></script>
Example:
<head>
<!-- ... other head content ... -->
<script src="myscript.js" type="text/javascript"></script>
</head>