Skip to contents

The following is an example of usage of the widget with JSON files. In this example, the JSON files are stored locally.


In this tutorial, we will serve the JSON files using a local web server.

Any static web server will work, and an easy one to install and configure is http-server.

Serve the JSON files locally

To serve the downloaded JSON files, move them to a new folder (for instance vitessce_json_example in the Downloads folder). Using the terminal, change directories to this folder containing the JSON files.

cd ~/Downloads/vitessce_json_example/

Serve the contents of this directory (the JSON files) using http-server:

http-server ./ --cors -p 8000

Configure the Vitessce widget

Add JSON files to the dataset using the add_file function. The add_file function returns the updated dataset, allowing the function calls to be chained.


base_url <- "http://localhost:8000/"

# Create Vitessce view config
vc <- VitessceConfig$new("Codeluppi et al., Nature Methods 2018")
dataset <- vc$add_dataset("Codeluppi")$add_file(
  url = paste0(base_url, "linnarsson.cells.json"),
  data_type = DataType$CELLS,
  file_type = FileType$CELLS_JSON
  url = paste0(base_url, "linnarsson.cell-sets.json"),
  data_type = DataType$CELL_SETS,
  file_type = FileType$CELL_SETS_JSON
  url = paste0(base_url, "linnarsson.molecules.json"),
  data_type = DataType$MOLECULES,
  file_type = FileType$MOLECULES_JSON
  url = paste0(base_url, "linnarsson.clusters.json"),
  data_type = DataType$EXPRESSION_MATRIX,
  file_type = FileType$CLUSTERS_JSON
  url = paste0(base_url, "linnarsson.raster.json"),
  data_type = DataType$RASTER,
  file_type = FileType$RASTER_JSON

desc <- vc$add_view(dataset, Component$DESCRIPTION)
desc <- desc$set_props(description = "Codeluppi et al., Nature Methods 2018: Spatial organization of the somatosensory cortex revealed by osmFISH.")

spatial <- vc$add_view(dataset, Component$SPATIAL)
spatial_layers <- vc$add_view(dataset, Component$LAYER_CONTROLLER)

scatterplot_pca <- vc$add_view(dataset, Component$SCATTERPLOT, mapping = "PCA")
scatterplot_tsne <- vc$add_view(dataset, Component$SCATTERPLOT, mapping = "t-SNE")
status <- vc$add_view(dataset, Component$STATUS)

cell_sets <- vc$add_view(dataset, Component$CELL_SETS)
gene_list <- vc$add_view(dataset, Component$GENES)
heatmap <- vc$add_view(dataset, Component$HEATMAP)$set_props(transpose = TRUE)

  vconcat(vconcat(desc, status), spatial_layers),
  vconcat(heatmap, spatial),
  vconcat(scatterplot_tsne, scatterplot_pca),
  vconcat(gene_list, cell_sets)

# Render the Vitessce widget
vc$widget(theme = "light")