subsetMaf() 查询参数无法从网页输入中获取闪亮的反应值。
subsetMaf() query argumet can't get Shiny reactive value from webpage input.
我正在做一些工作来显示网络服务器上由 maftools 生成的图片,但似乎 subsetMaf() "query" 参数无法从网络服务器获得闪亮的反应值输入。下面是一个简单的测试:
subsetMaf() 在 R 的控制台上运行良好,如下所示:
读取数据
library(magrittr)
mc3_pass <- readr::read_rds(file.path(config$database, "TCGA", "snv", "snv_mutation_mc3_public.pass.filtered_maf-4cancers.rds.gz")) # test data include clinical data, which include a column called "cancer_types"
mc3_pass临床数据如下所示,我想在临床数据
中过滤cancer_types
mc3_pass %>% maftools::getClinicalData()
Tumor_Sample_Barcode cancer_types
1: TCGA-05-4244-01A-01D-1105-08 LUAD
2: TCGA-05-4249-01A-01D-1105-08 LUAD
3: TCGA-05-4250-01A-01D-1105-08 LUAD
4: TCGA-05-4382-01A-01D-1931-08 LUAD
5: TCGA-05-4384-01A-01D-1753-08 LUAD
---
2245: TCGA-Z2-A8RT-06A-11D-A372-08 SKCM
2246: TCGA-Z2-AA3S-06A-11D-A397-08 SKCM
2247: TCGA-Z2-AA3V-06A-11D-A397-08 SKCM
2248: TCGA-Z7-A8R5-01A-42D-A41F-09 BRCA
2249: TCGA-Z7-A8R6-01A-11D-A41F-09 BRCA
控制台测试运行良好
ct <- reactive({c("LUAD")}) # pre define a object stored a cancer type name like reactive value in shiny.
query = as.expression("cancer_types %in% isolate(ct())") # define a query for filter, isolate() used to get the value of reactive value on console.
maftools::subsetMaf(mc3_pass, query = query, mafObj = T) -> gene_list_maf # subsetMaf filter
gene_list_maf %>%
maftools::getClinicalData() # check the filter results
在控制台上运行良好,cancer_types 过滤成功,如下所示。
Tumor_Sample_Barcode cancer_types
1: TCGA-05-4244-01A-01D-1105-08 LUAD
2: TCGA-05-4249-01A-01D-1105-08 LUAD
3: TCGA-05-4250-01A-01D-1105-08 LUAD
4: TCGA-05-4382-01A-01D-1931-08 LUAD
5: TCGA-05-4384-01A-01D-1753-08 LUAD
508: TCGA-NJ-A55O-01A-11D-A25L-08 LUAD
509: TCGA-NJ-A55R-01A-11D-A25L-08 LUAD
510: TCGA-NJ-A7XG-01A-12D-A397-08 LUAD
511: TCGA-O1-A52J-01A-11D-A25L-08 LUAD
512: TCGA-S2-AA1A-01A-12D-A397-08 LUAD
闪亮的反应值导致错误
在运行下面的代码之前,请删除之前生成的对象。
mc3_pass <- readr::read_rds(file.path(config$database, "TCGA", "snv", "snv_mutation_mc3_public.pass.filtered_maf-4cancers.rds.gz")) # test data include clinical data, which include a column called "cancer_types"
library(shiny)
Lung_choice <- list(
"Lung Adenocarcinoma(LUAD)" = "LUAD",
"Lung Squamous Cell Carcinoma(LUSC)" = "LUSC"
)
ui <- fluidPage(
checkboxGroupInput(inputId = "select",label = "Select cancers",
choices = Lung_choice),
actionButton("go",label = "Go"),
shiny::textOutput(outputId = "table")
)
server <- function(input, output, session) {
ct <- reactive({
input$select
})
observeEvent(input$go,{
print(ct())
print(class(ct()))
ct_2 <- as.character(ct())
print(ct_2)
# query = as.expression("cancer_types %in% ct()") # Error in ct: could not find function "ct"
# query = as.expression("cancer_types %in% ct_2") # Error in eval: object 'ct_2' not found
query = as.expression("cancer_types %in% input$select") # Error in eval: object 'input' not found
print(query)
maftools::subsetMaf(mc3_pass, query = query, mafObj = T) -> gene_list_maf # subsetMaf filter
print("maf done!")
gene_list_maf %>%
maftools::getClinicalData() %>%
dplyr::select(cancer_types) %>%
unique() %>% t() %>%
as.vector()->.x# check the filter results
print(".x done!")
output$table <- renderText({
return(.x)
})
print("out done!")
print(.x)
})
}
shinyApp(ui, server)
# Below is output shows that object ct() and ct_2 exactly stored the value from webpage input
[1] "LUAD"
[1] "character"
[1] "LUAD"
expression("cancer_types %in% input$select")
Warning: Error in eval: object 'input' not found
Stack trace (innermost first):
75: eval
74: eval
73: [.data.table
72: [
71: maftools::subsetMaf
70: observeEventHandler [#14]
4:
3: do.call
2: print.shiny.appobj
1:
我猜是环境的问题,但是我很难解决这个问题,你有什么建议吗?有什么办法可以解决这个问题吗?
非常感谢,任何建议都会有所帮助。
您的代码中的问题是 query = as.expression("cancer_types %in% input$select")
。
你可以通过将上面的代码替换为:
来解决这个问题
query = as.expression(paste0("cancer_types %in%'",input$select,"'"))
我们从 paste0("cancer_types %in%'",input$select,"'")
中得到的本质是
expression("cancer_types %in%'LUAD'")
。由于 input$select
不存在于 subsetMaf
函数的本地环境中,因此它正在创建错误,现在通过此更改我们正在传递存在于数据集中的 'LUAD'
。
编辑:
当所选输入大于一个时,您可以首先组合输入然后传递。代码如下:
InpSel <- paste0(input$select, collapse = "','")
query = as.expression(paste0("cancer_types %in% c('",InpSel,"')"))
希望对您有所帮助!
我正在做一些工作来显示网络服务器上由 maftools 生成的图片,但似乎 subsetMaf() "query" 参数无法从网络服务器获得闪亮的反应值输入。下面是一个简单的测试: subsetMaf() 在 R 的控制台上运行良好,如下所示:
读取数据
library(magrittr)
mc3_pass <- readr::read_rds(file.path(config$database, "TCGA", "snv", "snv_mutation_mc3_public.pass.filtered_maf-4cancers.rds.gz")) # test data include clinical data, which include a column called "cancer_types"
mc3_pass临床数据如下所示,我想在临床数据
中过滤cancer_typesmc3_pass %>% maftools::getClinicalData()
Tumor_Sample_Barcode cancer_types
1: TCGA-05-4244-01A-01D-1105-08 LUAD
2: TCGA-05-4249-01A-01D-1105-08 LUAD
3: TCGA-05-4250-01A-01D-1105-08 LUAD
4: TCGA-05-4382-01A-01D-1931-08 LUAD
5: TCGA-05-4384-01A-01D-1753-08 LUAD
---
2245: TCGA-Z2-A8RT-06A-11D-A372-08 SKCM
2246: TCGA-Z2-AA3S-06A-11D-A397-08 SKCM
2247: TCGA-Z2-AA3V-06A-11D-A397-08 SKCM
2248: TCGA-Z7-A8R5-01A-42D-A41F-09 BRCA
2249: TCGA-Z7-A8R6-01A-11D-A41F-09 BRCA
控制台测试运行良好
ct <- reactive({c("LUAD")}) # pre define a object stored a cancer type name like reactive value in shiny.
query = as.expression("cancer_types %in% isolate(ct())") # define a query for filter, isolate() used to get the value of reactive value on console.
maftools::subsetMaf(mc3_pass, query = query, mafObj = T) -> gene_list_maf # subsetMaf filter
gene_list_maf %>%
maftools::getClinicalData() # check the filter results
在控制台上运行良好,cancer_types 过滤成功,如下所示。
Tumor_Sample_Barcode cancer_types
1: TCGA-05-4244-01A-01D-1105-08 LUAD
2: TCGA-05-4249-01A-01D-1105-08 LUAD
3: TCGA-05-4250-01A-01D-1105-08 LUAD
4: TCGA-05-4382-01A-01D-1931-08 LUAD
5: TCGA-05-4384-01A-01D-1753-08 LUAD
508: TCGA-NJ-A55O-01A-11D-A25L-08 LUAD
509: TCGA-NJ-A55R-01A-11D-A25L-08 LUAD
510: TCGA-NJ-A7XG-01A-12D-A397-08 LUAD
511: TCGA-O1-A52J-01A-11D-A25L-08 LUAD
512: TCGA-S2-AA1A-01A-12D-A397-08 LUAD
闪亮的反应值导致错误
在运行下面的代码之前,请删除之前生成的对象。
mc3_pass <- readr::read_rds(file.path(config$database, "TCGA", "snv", "snv_mutation_mc3_public.pass.filtered_maf-4cancers.rds.gz")) # test data include clinical data, which include a column called "cancer_types"
library(shiny)
Lung_choice <- list(
"Lung Adenocarcinoma(LUAD)" = "LUAD",
"Lung Squamous Cell Carcinoma(LUSC)" = "LUSC"
)
ui <- fluidPage(
checkboxGroupInput(inputId = "select",label = "Select cancers",
choices = Lung_choice),
actionButton("go",label = "Go"),
shiny::textOutput(outputId = "table")
)
server <- function(input, output, session) {
ct <- reactive({
input$select
})
observeEvent(input$go,{
print(ct())
print(class(ct()))
ct_2 <- as.character(ct())
print(ct_2)
# query = as.expression("cancer_types %in% ct()") # Error in ct: could not find function "ct"
# query = as.expression("cancer_types %in% ct_2") # Error in eval: object 'ct_2' not found
query = as.expression("cancer_types %in% input$select") # Error in eval: object 'input' not found
print(query)
maftools::subsetMaf(mc3_pass, query = query, mafObj = T) -> gene_list_maf # subsetMaf filter
print("maf done!")
gene_list_maf %>%
maftools::getClinicalData() %>%
dplyr::select(cancer_types) %>%
unique() %>% t() %>%
as.vector()->.x# check the filter results
print(".x done!")
output$table <- renderText({
return(.x)
})
print("out done!")
print(.x)
})
}
shinyApp(ui, server)
# Below is output shows that object ct() and ct_2 exactly stored the value from webpage input
[1] "LUAD"
[1] "character"
[1] "LUAD"
expression("cancer_types %in% input$select")
Warning: Error in eval: object 'input' not found
Stack trace (innermost first):
75: eval
74: eval
73: [.data.table
72: [
71: maftools::subsetMaf
70: observeEventHandler [#14]
4:
3: do.call
2: print.shiny.appobj
1:
我猜是环境的问题,但是我很难解决这个问题,你有什么建议吗?有什么办法可以解决这个问题吗? 非常感谢,任何建议都会有所帮助。
您的代码中的问题是 query = as.expression("cancer_types %in% input$select")
。
你可以通过将上面的代码替换为:
来解决这个问题query = as.expression(paste0("cancer_types %in%'",input$select,"'"))
我们从 paste0("cancer_types %in%'",input$select,"'")
中得到的本质是
expression("cancer_types %in%'LUAD'")
。由于 input$select
不存在于 subsetMaf
函数的本地环境中,因此它正在创建错误,现在通过此更改我们正在传递存在于数据集中的 'LUAD'
。
编辑:
当所选输入大于一个时,您可以首先组合输入然后传递。代码如下:
InpSel <- paste0(input$select, collapse = "','")
query = as.expression(paste0("cancer_types %in% c('",InpSel,"')"))
希望对您有所帮助!