knitr::opts_knit$set(
  root.dir = dirname(dirname(getwd())),
  rmarkdown.pandoc.to = knitr::opts_knit$get("rmarkdown.pandoc.to")
)

The following is an example of usage of the widget with JSON files. In this example, the JSON files are stored on a remote AWS S3 bucket. For information about remote file hosting, please visit the Hosting Data page of the main Vitessce documentation website.

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 <- "https://s3.amazonaws.com/vitessce-data/0.0.31/master_release/linnarsson/"

# 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", width = "100%")
if(!is.null(knitr::opts_knit$get("rmarkdown.pandoc.to")) && knitr::opts_knit$get("rmarkdown.pandoc.to") == "html") {
  vc$widget(theme = "light", width = "100%")
}


vitessce/vitessce-r documentation built on Oct. 12, 2024, 11:47 p.m.