我可以将csv文件上传到服务器上,但不会在主面板或闪亮的仪表板主体面板中显示

时间:2019-07-18 11:43:30

标签: shiny shinydashboard shiny-reactivity

我正在使用Shiny App开发Web应用程序,但是对于Shiny和可用于构建App的仪表板不熟悉。我以将数据上传到服务器为例,但是上传后我无法在主面板或仪表板区域中查看。

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文件。

  
    

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

  

1 个答案:

答案 0 :(得分:0)

您正在使用变量input$header,但尚未创建。我建议删除服务器中的input$header,或在用户界面中创建input$header

从服务器删除它:

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) 

将其添加到用户界面:

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)