R Shiny App-数据表输出未呈现

时间:2018-09-14 15:29:00

标签: r shiny

以下是我为闪亮应用程序提供的代码。最终目的是使用户上载具有相同列标题的2个csv文件,并且输出应该是2个csv文件之间不同的行。该应用似乎可以正常上传CSV文件,但是闪亮的应用中没有显示表格。另外,我希望最终将完整的输出表导出到csv,但是我还没有将其包含在我的代码中。

library(shiny)
library(dplyr)
library(gridExtra)
library(grid)
library(stringr)
ui <- fluidPage(
  titlePanel("Uploading Files"),
  sidebarLayout(
    sidebarPanel(
      fileInput("file1", "Choose First Data File",
                    multiple = FALSE, accept = c("text/csv", "text/comma-separated-values, text/plain",
                                             ".csv")),
      fileInput("file2", "Choose Second Data File",
                multiple = FALSE, accept = c("text/csv", "text/comma-separated-values, text/plain",
                                             ".csv")),
      tags$hr(),
      checkboxInput("header", "Header", TRUE),
      radioButtons("sep", "Separator", choices = c(Comma = ",",
                                                   Semicolon = ";",
                                                   Tab = "\t"),
                   selected = ","),
      radioButtons("quote", "Quote", choices = c(None = "",
                                                 "Double Quote" = '"',
                                                 "Single Quote" = "'"),
                   selected = '"'),
      tags$hr(),
      radioButtons("disp", "Display", choices = c(Head = "head", All = "all"), selected = "head")
    ),
    mainPanel(
      tableOutput("contents", "export")
    )
  )
)
options(shiny.maxRequestSize = 30*1024^2)
server <- function(input, output) {
  data <- reactive({
    df <- read.csv(input$file1$datapath,
               header = input$header
               quote = input$quote)
    df2 <- read.csv(input$file2$datapath,
                header = input$header
                quote = input$quote)
    df$COLUMNA <- str_replace_all(df$COLUMNA, "[[:punct:]]", "")
    df2$COLUMNA <- str_replace_all(df2$COLUMNA, "[[:punct:]]", "")
    diff_df <- anti_join(df, df2, by = c("COLUMNA", "COLUMNB", "COLUMNC"))
    return(diff_df)
  }) 
}
output$contents <- renderTable({
  req(input$file1, input$file2)
  if(input$disp == "head") {
    head(data()$diff_df)
  }
  else {data()$diff_df}
})

shinyApp(ui, server)

0 个答案:

没有答案