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.

Setup

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.

library(vitessceR)

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

# Create Vitessce view config
vc <- VitessceConfig$new(schema_version = "1.0.16", name = "Codeluppi et al., Nature Methods 2018")
dataset <- vc$add_dataset("Codeluppi")$add_file(
  url = paste0(base_url, "linnarsson.cells.json"),
  file_type = FileType$CELLS_JSON,
  options = obj_list(
    embeddingTypes = c("PCA", "t-SNE")
  )
)$add_file(
  url = paste0(base_url, "linnarsson.cell-sets.json"),
  file_type = FileType$CELL_SETS_JSON
)$add_file(
  url = paste0(base_url, "linnarsson.molecules.json"),
  file_type = FileType$MOLECULES_JSON
)$add_file(
  url = paste0(base_url, "linnarsson.clusters.json"),
  file_type = FileType$CLUSTERS_JSON
)$add_file(
  url = paste0(base_url, "linnarsson.raster.json"),
  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$OBS_SETS)
gene_list <- vc$add_view(dataset, Component$FEATURE_LIST)
heatmap <- vc$add_view(dataset, Component$HEATMAP)$set_props(transpose = TRUE)

vc$layout(hconcat(
  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")