【发布时间】:2023-04-02 13:02:01
【问题描述】:
我正在开发一个应用程序(除其他外) 1. 允许用户上传 csv 数据集(这似乎可行) 2. 根据用户在单独选项卡中选择的文件绘制热图
应用程序似乎正在运行,但是我无法获取热图来绘制用户选择的数据,我认为它需要以某种方式进行响应,但我无法调用上传的文件。
到目前为止我的代码
用户界面: 图书馆(闪亮)
shinyUI(fluidPage(
tabsetPanel(
tabPanel("File Input",
sidebarLayout(
sidebarPanel(
fileInput("file","Upload the File"),
tags$hr(),
h5(helpText("Select the read.table parameters below")),
checkboxInput(inputId = 'header', label = 'Header', value = FALSE),
checkboxInput(inputId = "stringAsFactors", "stringAsFactors", FALSE),
br(),
radioButtons(inputId = 'sep', label = 'Separator', choices = c(Comma=',',Semicolon=';',Tab='\t', Space=''), selected = ',')
),
mainPanel(
uiOutput("tb")
)
)),
tabPanel("Heatmap",
plotOutput('heatmap', width = "100%", height = "500px")
))
))
服务器
library(shiny)
shinyServer(function(input,output,session){
data <- reactive({
file1 <- input$file
if(is.null(file1)){return()}
read.table(file=file1$datapath, sep=input$sep, header = input$header, stringsAsFactors = input$stringAsFactors)
})
output$filedf <- renderTable({
if(is.null(data())){return ()}
input$file
})
output$sum <- renderTable({
if(is.null(data())){return ()}
summary(data())
})
output$table <- renderTable({
if(is.null(data())){return ()}
data()
})
output$tb <- renderUI({
if(is.null(data()))
h5("Powered by copious amounts of coffee", tags$img(src='coffee.png', heigth=200, width=200))
else
tabsetPanel(tabPanel("About file", tableOutput("filedf")),tabPanel("Data", tableOutput("table")),tabPanel("Summary", tableOutput("sum")))
})
mps<-reactive({
if(is.null(file_to_read)){
return()
}
plots<-reactive({
output$heatmap <- renderPlot({ heatmap(data, main = "heatmap")
})})
})})
有没有办法将数据命名为要在热图中使用的对象,例如
mat<-as.matrix(user uploaded file, row.numbers=1)
output$heatmap <- renderPlot({ heatmap(mat, main = "heatmap")
【问题讨论】:
-
如果你使用
mat <- as.matrix(data(), row.numbers=1)会怎样? -
我已经尝试了一些变体,但热图选项卡仍然空白。
-
感谢它现在尝试生成热图,但出现错误警告“'x' must be a numeric matrix”。在选择上传文件之前和之后都会出现此错误,这就是为什么我认为一旦选择了数据集,我就必须使函数及其组件具有反应性以重现绘图。
-
@Niall 你能把你的问题编辑成你目前在你的代码中有什么供审查吗?我能够在没有任何错误的情况下进行复制。你在尝试什么数据文件?是否可以创建
character矩阵而不是numeric?您可能希望转换为没有行名的矩阵,然后再添加行名。
标签: r shiny heatmap bioinformatics reactive