首页 > 解决方案 > 我可以在服务器上上传 csv 文件,但它没有显示在主面板或闪亮的仪表板主体面板中

问题描述

我正在使用闪亮的应用程序开发一个 Web 应用程序,我对可用于构建应用程序的闪亮和仪表板不熟悉。我举了一个将数据上传到服务器的例子,但上传后我无法在主面板或仪表板区域查看。

library(shiny)
library(shinydashboard)
ui <- dashboardPage(
  dashboardHeader(title = strong ("OMNALYSIS")),
  dashboardSidebar(fileInput("file1", "Upload Expression Data",
                                accept = c(
                                  "text/csv",
                                  "text/comma-separated-values,text/plain",
                                  ".csv"),

  )),
  dashboardBody(
    tableOutput("contents")

  )
)
server <- function(input, output) {`enter code here`
  output$contents <- renderTable({

    inFile <- input$file1

    if (is.null(inFile))
      return(NULL)

    read.csv(inFile$datapath, header = input$header)
  })
}

shinyApp(ui, server)         

我希望查看用户上传到主面板或闪亮仪表板空间的 csv 文件。

错误 - 警告:错误!:无效的参数类型。

标签: shinyshinydashboardshiny-reactivity

解决方案


您正在使用该变量input$header,但它没有被创建。我建议删除input$header服务器中的,或input$header在 UI 中创建。

从服务器中删除它:

library(shiny)
library(shinydashboard)
ui <- dashboardPage(
  dashboardHeader(title = strong ("OMNALYSIS")),
  dashboardSidebar(fileInput("file1", "Upload Expression Data",
                             accept = c(
                               "text/csv",
                               "text/comma-separated-values,text/plain",
                               ".csv")
                             
  )),
  dashboardBody(
    tableOutput("contents")
  )
)
server <- function(input, output) {#'enter code here'
  output$contents <- renderTable({
    inFile <- input$file1
    if (is.null(inFile))
      return(NULL)
    read.csv(inFile$datapath)
  })
}   
shinyApp(ui, server) 

将其添加到 UI:

library(shiny)
library(shinydashboard)
ui <- dashboardPage(
  dashboardHeader(title = strong ("OMNALYSIS")),
  dashboardSidebar(fileInput("file1", "Upload Expression Data",
                             accept = c(
                               "text/csv",
                               "text/comma-separated-values,text/plain",
                               ".csv")),
  checkboxInput("header", "Header")
  ),
  dashboardBody(
    tableOutput("contents")
    
  )
)
server <- function(input, output) {#'enter code here'
  output$contents <- renderTable({
    inFile <- input$file1
    if (is.null(inFile))
      return(NULL)
    read.csv(inFile$datapath, header = input$header)
  })
}
shinyApp(ui, server) 

推荐阅读