首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用闪亮的、查询和显示数据

使用闪亮的、查询和显示数据
EN

Stack Overflow用户
提问于 2019-06-27 02:29:56
回答 1查看 175关注 0票数 0

我有几个问题:(a)使用Rshiny以交互模式显示数据(2)查询mongodb查询的结果。下面给出了我的代码,它看起来像独立的部分,但不能很好地结合在一起。

对于问题(a),我以前使用过Output$values,这似乎是可行的。在问题(b)的代码中注释掉了,我使用mongolite R包来查询数据,并使用reactive来传递查询。

代码语言:javascript
运行
复制
library(data.table)
library(tidyverse)
library(shiny)
library(mongolite)

epi <- read.csv("./data/Genes.csv", header=T)
label = "gene"
epilist <- data.frame(epi$gene, label)
names(epilist) = c("value", "label")

df <- read.table("./data/CCLE_meta.csv", header=TRUE, sep=",", na.strings="NA", fill=TRUE)
dd <- data.frame((df$Tissue))
names(dd) = "Tissue"
cell1= dd %>% add_row(Tissue = "all")
label = "Tissue"
cell <- data.frame(cell1$Tissue, label)
names(cell) = c("value", "label")

ui <- fluidPage(

  titlePanel("Dependencies for EpiGenes"),

  sidebarLayout(
    sidebarPanel(
      selectizeInput("epiInput","gene", choices=NULL, selected=NULL),
      selectizeInput("cellInput","Tissue", choices=NULL, selected=NULL),
      textOutput("values")
    ),

    mainPanel(
      tabsetPanel(type = "tabs",
        tabPanel("Fusions", tableOutput("table")),
        tabPanel("CancerGD", tableOutput("table")),
        tabPanel("CCLEmeta", tableOutput("table")),
        tabPanel("EpiGenes", tableOutput("table"))
      )
    )
  )
)


server <- function(input, output, session) {
  updateSelectizeInput(session, 'epiInput',
                       choices = epilist$value,
                       server = TRUE)
  updateSelectizeInput(session, 'cellInput',
                       choices = cell$value,
                       server = TRUE)

  #output$values <- renderText({
  #  paste(input$epiInput, input$cellInput)
  #})


  ### Looking into Epi Genes

  con1 <- mongo(collection = "Genes", db = "discovery", url = "mongodb://127.0.0.1:27017")
  data.for.table1 <- reactive({
    query.foo <- paste0('{"gene" : epiInput}')
    con1$find(query = query.foo, limit = 100)
  })
  output$EpiGenes <- renderDataTable({
    data.for.table1()
  })

  ### Looking into Cell Line Metadata

  con0 <- mongo(collection = "CellLine", db = "discovery", url = "mongodb://127.0.0.1:27017")
  data.for.table0 <- reactive({
    query.foo <- paste0('{"Tissue" : input$cellInput}')
    con0$find(query = query.foo, limit = 100)
  })
  output$CCLEmeta <- renderDataTable({
    data.for.table0()
  })

  ### Looking into fusion genes
  con2 <- mongo(collection = "fusions", db = "discovery", url = "mongodb://127.0.0.1:27017")
  data.for.table2 <- reactive({
    query.foo <- paste0('{"gene" : input$epiInput}')
    con2$find(query = query.foo, limit = 100)
  })
  output$Fusions <- renderDataTable({
    data.for.table2()
  })

  ### Looking into CancerGD

  con3 <- mongo(collection = "CancerGD", db = "discovery", url = "mongodb://127.0.0.1:27017")
  data.for.table3 <- reactive({
    query.foo <- paste0('{"gene" : input$epiInput}')
    con3$find(query = query.foo, limit = 100)
  })
  output$CancerGD <- renderDataTable({
    data.for.table3()
  })

  # Automatically disconnect when connection is removed
  rm(con0)
  rm(con1)
  rm(con2)
  rm(con3)
  gc()

}
shinyApp(ui, server)

第一个预期的输出是一个应用程序,允许用户从基因和组织列表中进行查询。第二个预期输出是在适当的选项卡中显示查询结果(来自数据库发现的4个集合)。当前结果是一个没有查询功能的应用程序。

EN

Stack Overflow用户

发布于 2019-06-27 21:56:22

我可以对代码做一些修改,现在我得到的错误/挂起是

“已导入0条记录。简化为数据帧...”

对错误的任何洞察都将是有帮助的。

对代码的改进如下:

(a) SidebarPanel

代码语言:javascript
运行
复制
selectizeInput("epiInput","gene", choices=gg),
selectizeInput("cellInput","Tissue", choices=cc),

(b)连接到MongoDB

代码语言:javascript
运行
复制
con2 <- mongo(collection="fusions", db="discovery", url="mongodb://localhost:27017", verbose = TRUE)
  fusResults <- reactive({
      region <- list(gene = input$epiInput)
      query.foo <- paste0('{ "gene" : "',region , '"}')
      fs <- con2$find(query = query.foo, limit = 100)
      return(fs)
  })

 output$fus_results <- renderDataTable({
    fusResults()
  })
票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56779063

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档