首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >上传后的r亮显示数据帧

上传后的r亮显示数据帧
EN

Stack Overflow用户
提问于 2019-04-05 21:16:37
回答 1查看 1.2K关注 0票数 0

我正在努力建立一个记录链接应用在R发亮。我使用R已经有一段时间了,但是我还不太清楚。我的问题是,我正在努力弄清楚如何显示我通过fileInput上传的文件。我的密码在下面。

代码语言:javascript
复制
library(shiny)
library(shinydashboard)

用户界面

代码语言:javascript
复制
ui <- dashboardPage(
  dashboardHeader(title = "Record Linkage App"),
  dashboardSidebar(
    sidebarMenu(
      ## Tab 1 -- Specify Task
      menuItem("Select Task And Upload Files", tabName = "task", icon = 
    icon("file-text-o")),
  ## Tab 2 -- View Raw Data Files
  menuItem("View Raw Data", tabName = "raw", icon = icon("file-text-o")),
  ## Tab 3 -- View Processed Data Files
  menuItem("View Processed Data", tabName = "processed", icon = icon("file-text-o")),
  ## Tab 4 -- Select Training Set
  menuItem("Select Training Set", tabName = "mltrain", icon = icon("file-text-o")),
  ## Tab 5 -- View Weight & Probabilities (choose which chart to view or both?)
  menuItem("Visualize Distributions", tabName = "distributions", icon = icon("bar-chart-o")),
  ## Tab 6 -- View Results (review, match and trash files--need to be able to choose dataset)
  ## Want to be able to add checkboxes to select rows for inclusion in deletion later on
  menuItem("View Result Files", tabName = "fileview", icon = icon("file-text-o"))

)), # close dashboard sidebar

  #### Dashboard Body starts here

  dashboardBody(
    tabItems(
  ### Specify Task & Upload Files Tab
  tabItem(tabName = "task",
          radioButtons("task", "Select a Task:", c("Frame Deduplication", "Frame Record Linkage")),
          fileInput("selection", "Upload Files:", multiple = T, 
                    accept = c(".xls", "text/csv", "text/comma-separated-values, text/plain", ".csv")),
          helpText(paste("Please upload a file.  Supported file types are:  .txt, .csv and .xls"))

          ), # close first tabItem

  tabItem(tabName = "raw",
          helpText(paste("This tab displays the raw, unprocessed data frames selected in the previous tab.")),
          mainPanel(
            tableOutput("contents")

          )

) # close tabItems

  ) # close dashboardBody
) #close dashboardpage

)

服务器

代码语言:javascript
复制
server <- function(input, output, session) {
   output$contents <- renderTable({
      req(input$file1)
      read.csv(input$file1$datapath)

  })
}

shinyApp(ui, server)

我希望能够在标签"raw“中显示该表。

我的问题是: 1.如果我只想显示表,它需要是reactive吗?

  1. input$file1$datapath如何进入renderTable

如有任何建议或建议,将不胜感激。谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-05 22:52:37

我认为您对文档的理解有点过于严格了:您应该引用input$selection,而不是input$file1。我将您的服务器组件修改为此,它起了作用:

代码语言:javascript
复制
server <- function(input, output, session) {
  output$contents <- renderTable({
    req(input$selection)
    read.csv(input$selection$datapath)
  })
}

顺便说一句:虽然没有伤害到任何东西,但你使用的是mainPanel,它通常与shiny::sidebarLayout一起使用在非仪表板应用中。但是,由于您使用的是shinydashboard,所以这是不必要的,您可以将最后一个tabItem减少到

代码语言:javascript
复制
      tabItem(tabName = "raw",
              helpText(paste("This tab displays the raw, unprocessed data frames selected in the previous tab.")),
              tableOutput("contents")
              )
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55543482

复制
相关文章

相似问题

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