yueqiw / shiny_cell_browser

Shiny browser for single cell RNAseq data
9 stars 3 forks source link

runapp failed #5

Closed skytguuu closed 4 years ago

skytguuu commented 4 years ago

Hi,

I tried to use ur shinyapp but it failed. After I check the code, it maybe caused by my seurat version. I used seurat version 3 but your code seems used with seurat v2. Could you revised the code? Another question about the json data, I am not sure my json data is right or not. As followed:

############## { "data": [ { "name": "My favorite sample", "file": "./pb26_integrated.rds", "clusters": "integrated_snn_res.0.1", "embedding": "umap" } ], "config": { "startup_data1": 1, "default_layout": "horizontal", "default_viz_mode": "interactive", "default_single_gene": "none" }

} ######################## Finally, I am still confused about the code in your line 31 in server.R: seurat_data <- readRDS(x$file). As my understanding, x is represented the json_data. But the json_data could not use "$". Followed is my error report:

################## Error in gzfile(file, "rb") : cannot open the connection In addition: Warning message: In gzfile(file, "rb") :

Hide Traceback

Rerun with Debug Error in gzfile(file, "rb") : cannot open the connection 4. gzfile(file, "rb") 3. readRDS(x$file) 2. FUN(X[[i]], ...) 1. lapply(json_data, read_data) ####################################

Could you give me a hand?

Thanks! Best, Garen

yueqiw commented 4 years ago

Hi Garen,

Thanks for trying out the code!

  1. I made a few edits today and it should support Seurat 3 datasets now. Please check out the code in the seurat3 branch.

    git pull
    git checkout seurat3
  2. The example json file was a bit outdated. Please follow the updated example and README.

  3. For the json error, it could be due to a wrong file path. json_data is represented as a list structure, so x$file should be a valid string for the file path.

Let me know if you have other questions!

Yueqi

skytguuu commented 4 years ago

Hi Yueqi,

Thanks for ur quickly reply. I have tried ur revised code, however it failed again. After I checked the code, it seems u added the function code as followed:

######################## SetAllIdent <- function(object, ids) { Idents(object) <- ids return(object) }

GetClusters <- function(object) { clusters <- data.frame(cell.name = names(object@active.ident), cluster = object@active.ident) rownames(clusters) <- NULL clusters$cell.name <- as.character(clusters$cell.name) return(clusters) }

GetDimReduction <- function(object, reduction.type = "umap", slot = "cell.embeddings") { reduction <- object[[reduction.type]] return(eval(expr = parse(text = paste0("reduction", "@", slot)))) } ########################### But it did not work. The error is the same:

################### image

data_list <- lapply(json_data, read_data) Error in gzfile(file, "rb") : cannot open the connection In addition: Warning message: In gzfile(file, "rb") :

Hide Traceback

Rerun with Debug Error in gzfile(file, "rb") : cannot open the connection 4. gzfile(file, "rb") 3. readRDS(x$file) 2. FUN(X[[i]], ...) 1. lapply(json_data, read_data) ####################### It seems I cannot readRDS rightly. I don't know it because of my windows system or the json_data problem (code is : seurat_data <- readRDS(x$file) My json is as followed: ################## { "data": [ { "name": "My favorite sample", "file": "./pb26_integrated.rds", "clusters": "integrated_snn_res.0.1", "embedding": "umap" } ], "config": { "startup_data1": 1, "default_layout": "horizontal", "default_viz_mode": "interactive", "default_single_gene": "none" }

}

{ "data": [ { "name": "My 1st sample", "file": "./pb26_integrated.rds", "cluster": "res.1", "embedding": "umap", "diff_ex_cluster": "res.1", "diff_ex_file": "./gene.csv" }, { "name": "My 2nd sample", "file": "./pb26_integrated.rds", "cluster": "res.1_rename1", "embedding": "tsne", "diff_ex_cluster": "res.1", "diff_ex_file": "./gene.csv",

        "cluster_name_mapping": {
            "C1": "Neurons",
            "C2": "Astrocytes",
            "C3": "Neural Progenitors",
            "Note": "cluster_name_mapping is optional"
        },
        "pt_size": 2,
        "font_scale": 0.75
    }
],
"config": {
    "ui_title": "Single Cell Browser",
    "title_link_text": "Optional subtitle (e.g. your lab)",
    "title_link_url": "http://optional-link-to-your-lab.com"
}

} ####################

Thank you for your help! Best, Garen

yueqiw commented 4 years ago

Are you able to read the file in R console? For example, setwd to the app directory, and data <- readRDS("./pb26_integrated.rds"). Make sure the file path is correct before launching the app. If the data is stored in shiny_cell_browser/data, then your file path should be data/pb26_integrated.rds.

Then copy the first few lines into the console,

json_file <- rjson::fromJSON(file = './data/config.json')
json_data <- json_file$data

and try seurat_data <- readRDS(json_data[[1]]$file)

I don't have a Windows system but I'm pretty sure it should work.

skytguuu commented 4 years ago

Hi,

I have tried the server.R code step by step. The data can be read with readRDS("./pb26_integrated.rds"). And also it worked with readRDS(json_data[[1]]$file). But when I tried to use ur read_data function, it failed. That's why I am confused about the json data and "$". Now, as ur advise, I tried the working directory with "setwd("E:/Bio-anlysis-code/Shinyapp/test/shiny_cell_browser/data")" and setwd("E:/Bio-anlysis-code/Shinyapp/test/shiny_cell_browser"), both were failed. The former one reported that "Error in shinyAppDir(x) : App dir must contain either app.R or server.R.". It seems that there are only .json and .rds file in this folder without the app.R. While, when I set the working directory with "shiny_cell_browser", it reported the same error. I used the command "shiny::runApp('./', host='0.0.0.0',port=1234)" to try ur shinyapp in my Rstudio. "pb26_integrated.rds" was both in data file and shiny_cell_browser file.

This is my R sessioninfo: image

I am appreciated for your help.

Thanks, Best, Garen

yueqiw commented 4 years ago

solved after offline discussion.