比较来自两个下拉菜单 R Shiny 的 CSV 文件

Compare CSV files from two dropdowns Rshiny

如何使用 ./data 文件夹中的 csv 文件创建一个带有两个下拉菜单的闪亮应用,然后读取这些 Csv 并比较差异?

用户从两个下拉菜单中选择 CSV,然后自动生成差异

UI.R

library("shiny")

ui <- fluidPage(
  fluidPage(
    titlePanel("Automated Data Dictionary Comparison"),
    sidebarLayout(

      sidebarPanel(

        selectInput(inputId = 'Dic1',
                    label = 'Choose First Data Dictionary:',
                    choices = list.files(path = "./data",
                                         full.names = FALSE,
                                         recursive = FALSE)),
        selectInput(inputId = 'Dic2',
                    label = 'Choose Second Data Dictionary:',
                    choices = list.files(path = "./data",
                                         full.names = FALSE,
                                         recursive = FALSE))
      ),

      mainPanel(
        tableOutput('contents')
      )
    )
  )
)

SERVER.R

Library(shiny)
library(dplyr)

 server <-  function(input, output) {

   dataset <- reactive({
     infile <- input$Dic1

     if (is.null(infile)){
       return(NULL)
     }
     read.csv(infile[[1]])
   })

   output$contents <- renderDataTable({

     #x <- dataset()
     Diff <- render_diff(diff_data(data_ref=input$DIC1, data = input$DIC2),
     Diff
   })

 }

从我在这里看到的情况来看,您正在做的是正确地创建了您的反应数据集对象 dataset(对于您的输入文件中的 1 个,但不是两个),但是稍后,当您想生成差异时,您不会使用它 table (这又需要是一个反应性组件,因为它将由 2 个反应性组件生成 - dataset1dataset2)。

像这样的东西应该可以解决问题(将其包装在服务器函数中):

# Parse first file
dataset1 <- reactive({
  infile <- input$Dic1

  if (is.null(infile)){
    return(NULL)
  }
  x <- read.csv(infile[[1]])
  x
})
# Parse second file
dataset2 <- reactive({
  infile <- input$Dic2

  if (is.null(infile)){
    return(NULL)
  }
  x <- read.csv(infile[[1]])
  x
})
# Create comparison table (reactive as both of its elements are reactive)
diff <- reactive({
  x <- render_diff(diff_data(data_ref=dataset1(), data=dataset2()))
  x
})
#Output
output$contents <- renderDataTable({
  diff()
})

检查上面的内容,让我知道你的情况。