Use the HISE SDK to Create Visualizations (Tutorial)

Last modified 2025-01-06

Abbreviations Key
HISEHuman Immune System Explorer
IDEintegrated development environment

At a Glance

When you visualize a data set that's instrumental to your research, you can share your results with other scientists and save your visualization to a template. Templates let you document your methodology, tools stack, and input data, so that others can reproduce your results. 

This document explains how to create a visualization template and save it to HISE so that any other HISE user can repurpose it create their own interactive visualization. 

Components

When you save a visualization in HISE, the IDE instance itself (but not the home/jupyter directory) is recorded, including the following components:

By default, visualizations are saved  in Draft mode. You can use this stage to review the results with your collaborators. If you're not satisfied with the visualization, you can delete it and create an improved version. When you're happy with the result, you can switch the visualization mode to Final. Note that only final visualizations can be used in publications and Data Apps.

Paths

TypeDescriptionPreprocessingLibrary
Simple visualizationsSingle figuresR or PythonPlotly based–includes support in R for the ggplot library
Complex visualizationsInteractive figures or figures with multiple graphsFor rapid rendering, load data without preprocessing if possible. Any necessary preprocessing can be done in R or Python.Dash based

There are two paths to creating a saved visualization, as shown in the accompanying table.

Simple Visualizations

In the examples folder within your HISE IDE instance, the Plotly subfolders (under "Python" and under "R") contain example figures you can use as the basis of a simple visualization, supplying your own data frames. The folder also contains information on how to save visualizations to a study, either by using a UI widget to facilitate parameter value selection or by manually providing the parameter. 

Complex Visualizations

In the examples folder of your HISE IDE instance, use Markdown Preview to open the ReadMe.md file, which explains the concepts and approach to complex visualizations, and guides you through the various notebooks of sample code.


Instructions

Read from the remote bucket

For a visualization template to work, the visualization must be read from a cloud storage bucket. The visualization is stored separately from the data. This decoupling enables the creation of multiple instances of a visualization, each of which pulls data from a different source. 

1. Log in to HISE.

2. From the top navigation, choose COLLABORATION SPACE > IDE instances.

3. Create an IDE instance. For details, see Work with IDE Instances.

4. To parse the URL that points to the remote location of the data set and reads in its contents as a data.frame, use the init_data() function, as shown below:

parsed_url = urlparse(search)data_url = parse_qs(parsed_url.query)['data-url'][0]logger.info("reading data: %s", data_url)df = pd.read_json(data_url

Set the port number

Next, set the port number and debug flag in the main app.py function.

1. To set the port number to 8050 and set the debug flag to False, use the app.run_server() function:

if __name__ == '__main__':

logger.info("running app server")

app.run_server(host='0.0.0.0', port=8050, debug=False)

Save your template to HISE

To save your work to HISE, adjust the environment.yml config file (only if needed) and call hisepy.save_abstraction().

1. To create an environment.yml file, create and activate a conda environment, and install the application packages. For details, see Installing conda.

2. In your terminal, execute the following command:

conda env export > environment.yml

3. Create a tar file that contains your app.py script and the contents of /home/jupyter/demo-hise-api/demos/Visualization_apps/dash/configs. If you have Python packages or libraries that aren't already specified in the file, replace the .yml file with the one that already exists.

4. To save your visualization template to HISE, call hisepy.save_abstraction():

hp.save_abstraction(app_filepath='/home/jupyter/examples/Visualization_apps/dash/app.py',

title="Title",description="Description",result_file_types=["scRNA-seq-labeled"],

image='/home/jupyter/examples/Visualization_apps/dash/image.png',

data_contract_id="09a19b05-a34d-4d12-bc0b-e59a5e35be87",additional_files=[])

(Optional): Save a template that uses only sample or subject metadata

To save a template that uses only sample or subject metadata, you must set two additional parameters.

1. To execute the hisepy.save_abstraction() function, enter the following code block:

hp.save_abstraction(app_filepath='/home/jupyter/examples/Visualization_apps/dash/app.py',

title="Title", description="Description",

is_sample_metadata_app = True,

image='/home/jupyter/examples/Visualization_apps/dash/image.png',

data_contract_id="09a19b05-a34d-4d12-bc0b-e59a5e35be87",

additional_files=[])

2. To determine which string value to pass into the result_file_type parameter, use the utility function hisepy.get_result_files().This function returns a data.frame with the following columns: id, fileType, description, and isSearchable. If the incorrect string value is inserted, the function returns an error and prints a list of all possible valid values.


NOTE

Plotly visualizations sometimes return a ValueError. This error is caused by outdated Python dependencies or by incompatibilities between Plotly and the IDE environment. It can occur when you try to render a visualization using fig.show(), often after you update to a new version of Plotly. The error can also occur randomly. To resolve the issue, take the following steps:

  1. Update your dependencies. Open a terminal or command prompt and run the following commands:

    conda update -n base -c conda-forge conda

    conda install nbformat

  2. Use an iframe to render your visualization. To render your visualization in an iframe, add the following lines to the beginning of your script:

    import plotly.io as pio

    pio.renderers.default = 'iframe'

  3. Specify iframe in your function call. When you call fig.show(), specify iframe, as shown below:

    fig.show('iframe')

Following is an example implementation of the above solution. Remember to update Conda as a first step.

import plotly.io as pio

pio.renderers.default = 'iframe'

fig = px.scatter(filtered_data, x="gdpPercap", y="lifeExp",

   size="pop", color="continent",

hover_name="country", log_x=True, size_max=60)

fig.show('iframe')


Related Resources

Explore No-Code Visualizations

Create Your First IDE Instance

Create and Manage an IDE