vitessce / vitessceR

R API and htmlwidget for Vitessce
https://r-docs.vitessce.io
Other
38 stars 9 forks source link

vitessceR works locally but shinyapps.io deployment failed to show cells #92

Closed chunhuicai closed 2 weeks ago

chunhuicai commented 2 months ago

Hey there,

I'm using VitessceR to create a visualization for my dataset. It works perfectly on my local machine, but after following the tutorial (https://r-docs.vitessce.io/articles/shiny.html) to deploy it to ShinyApps.io, the PCA plot shows 0 cells.

Local: Screenshot 2024-08-28 at 5 35 40 PM

shinyapp.io: Screenshot 2024-08-28 at 5 30 02 PM

I preprocessed the RDS file into Zarr files on my local machine and then uploaded them to ShinyApps.io for visualization. I'm not sure if this is causing the issue, or if I need to set up a Python environment on ShinyApps.io, as suggested by the log warning message during deployment. My code and the ShinyApps.io log file are provided below. Any help would be greatly appreciated!

  1. data_prep.R

pbmc <- readRDS("~/BCH_projects/CellxGene_VM/shinyapp_mini/data/seurat/BA4_seuratobj.rds")

BASE_DIR <- file.path("data", "seurat") adata_filename <- "pbmc3k.final.h5ad.zarr" vitessceAnalysisR::seurat_to_anndata_zarr(pbmc, file.path(BASE_DIR, adata_filename))

  1. ui.R

library(shiny) library(vitessceR)

ui <- fluidPage( paste0("Vitessce in a Shiny app, zarr folder exist:", file.exists("data/seurat/pbmc3k.final.h5ad.zarr/")), vitessce_output(output_id = "vitessce_visualization", height = "600px"), )

  1. server.R (local)

library(shiny) library(vitessceR) library(vitessceAnalysisR) library(Seurat)

BASE_DIR <- file.path("data", "seurat") adata_filename <- "pbmc3k.final.h5ad.zarr"

w <- AnnDataWrapper$new( adata_path=adata_filename, obs_embedding_paths = c("obsm/X_pca", "obsm/X_spatial"), obs_embedding_names = c("PCA", "UMAP"), obs_set_paths = c("obs/H1_annotation", "obs/H2_annotation") )

server <- function(input, output, session) {
output$vitessce_visualization <- render_vitessce(expr = {

vc <- VitessceConfig$new(schema_version = "1.0.16", name = "My config", base_dir = BASE_DIR)
dataset <- vc$add_dataset("My dataset")
dataset <- dataset$add_object(w)
scatterplot <- vc$add_view(dataset, Component$SCATTERPLOT, mapping = "PCA")
vc$layout(scatterplot)

vc$widget(theme="light")

}) }

  1. server.R (remote:shinyapp.io)

library(shiny) library(vitessceR) library(vitessceAnalysisR) library(Seurat)

BASE_DIR <- file.path("data", "seurat") adata_filename <- "pbmc3k.final.h5ad.zarr"

w <- AnnDataWrapper$new( adata_path=adata_filename, obs_embedding_paths = c("obsm/X_pca", "obsm/X_spatial"), obs_embedding_names = c("PCA", "UMAP"), obs_set_paths = c("obs/H1_annotation", "obs/H2_annotation") )

server <- function(input, output, session) { addResourcePath("shinyapp_vitessce_example", BASE_DIR)

output$vitessce_visualization <- render_vitessce(expr = {

vc <- VitessceConfig$new(schema_version = "1.0.16", name = "My config", base_dir = BASE_DIR)
dataset <- vc$add_dataset("My dataset")
dataset <- dataset$add_object(w)
scatterplot <- vc$add_view(dataset, Component$SCATTERPLOT, mapping = "PCA")
vc$layout(scatterplot)

vc$widget(theme = "light", serve = FALSE, base_url = "https://myshinyapp-chunhui.shinyapps.io/shinyapp_vitessce_example/")

}) }

Log file:

2024-08-28T21:28:50.217442+00:00 shinyapps[12541383]: Container event from container-10070181: start 2024-08-28T21:28:52.234066+00:00 shinyapps[12541383]: Running on host: dc0b58d05472 2024-08-28T21:28:52.238930+00:00 shinyapps[12541383]: Running as user: uid=10001(shiny) gid=10001(shiny) groups=10001(shiny) 2024-08-28T21:28:52.244261+00:00 shinyapps[12541383]: Connect version: 2024.05.0 2024-08-28T21:28:52.249226+00:00 shinyapps[12541383]: LANG: C.UTF-8 2024-08-28T21:28:52.253811+00:00 shinyapps[12541383]: Working directory: /srv/connect/apps/shinyapp_vitessce_example 2024-08-28T21:28:52.258579+00:00 shinyapps[12541383]: Using R 4.4.1 2024-08-28T21:28:52.263258+00:00 shinyapps[12541383]: R.home(): /opt/R/4.4.1/lib/R 2024-08-28T21:28:52.267841+00:00 shinyapps[12541383]: Content will use current R environment 2024-08-28T21:28:52.272826+00:00 shinyapps[12541383]: R_LIBS: (unset) 2024-08-28T21:28:52.277550+00:00 shinyapps[12541383]: .libPaths(): /usr/lib/R, /opt/R/4.4.1/lib/R/library 2024-08-28T21:28:52.282528+00:00 shinyapps[12541383]: shiny version: 1.9.1 2024-08-28T21:28:52.287348+00:00 shinyapps[12541383]: httpuv version: 1.6.15 2024-08-28T21:28:52.292827+00:00 shinyapps[12541383]: rmarkdown version: 2.28 2024-08-28T21:28:52.297373+00:00 shinyapps[12541383]: knitr version: 1.48 2024-08-28T21:28:52.301955+00:00 shinyapps[12541383]: jsonlite version: 1.8.8 2024-08-28T21:28:52.306759+00:00 shinyapps[12541383]: RJSONIO version: (none) 2024-08-28T21:28:52.311440+00:00 shinyapps[12541383]: htmltools version: 0.5.8.1 2024-08-28T21:28:52.316080+00:00 shinyapps[12541383]: reticulate version: 1.38.0 2024-08-28T21:28:52.321158+00:00 shinyapps[12541383]: Warning: The reticulate package is installed but no Python environment is available. 2024-08-28T21:28:52.325977+00:00 shinyapps[12541383]: Did you forget to set the RETICULATE_PYTHON environment variable in your .Rprofile before publishing? 2024-08-28T21:28:52.330900+00:00 shinyapps[12541383]: Using pandoc: /opt/connect/ext/pandoc/2.16 2024-08-28T21:28:52.335820+00:00 shinyapps[12541383]: 2024-08-28T21:28:52.340542+00:00 shinyapps[12541383]: Starting R with process ID: '32' 2024-08-28T21:28:52.345472+00:00 shinyapps[12541383]: Shiny application starting ... 2024-08-28T21:28:52.350164+00:00 shinyapps[12541383]: 2024-08-28T21:28:52.354751+00:00 shinyapps[12541383]: Listening on http://127.0.0.1:44429 2024-08-28T21:28:52.729320+00:00 shinyapps[12541383]: Container event from container-10070117: stop 2024-08-28T21:29:02.201789+00:00 shinyapps[12541383]: 2024-08-28T21:29:02.207276+00:00 shinyapps[12541383]: Attaching package: ‘vitessceAnalysisR’ 2024-08-28T21:29:02.211985+00:00 shinyapps[12541383]: 2024-08-28T21:29:02.216686+00:00 shinyapps[12541383]: The following object is masked from ‘package:vitessceR’: 2024-08-28T21:29:02.221617+00:00 shinyapps[12541383]: 2024-08-28T21:29:02.226272+00:00 shinyapps[12541383]: obj_list 2024-08-28T21:29:02.230940+00:00 shinyapps[12541383]: 2024-08-28T21:29:02.235512+00:00 shinyapps[12541383]: Loading required package: SeuratObject 2024-08-28T21:29:02.240643+00:00 shinyapps[12541383]: Loading required package: sp 2024-08-28T21:29:03.207205+00:00 shinyapps[12541383]: 2024-08-28T21:29:03.212056+00:00 shinyapps[12541383]: Attaching package: ‘SeuratObject’ 2024-08-28T21:29:03.216754+00:00 shinyapps[12541383]: 2024-08-28T21:29:03.221626+00:00 shinyapps[12541383]: The following objects are masked from ‘package:base’: 2024-08-28T21:29:03.226996+00:00 shinyapps[12541383]: 2024-08-28T21:29:03.232345+00:00 shinyapps[12541383]: intersect, t 2024-08-28T21:29:03.237159+00:00 shinyapps[12541383]:

Best, Chunhui