Below is the code I have for my shiny app. The ultimate goal is for the user to upload 2 csv files that have the same column titles and the output should be the rows that are different between the 2 csv files. The app seems to upload the csv files OK, but there is no table shown in the shiny app. Additionally, I hope to export the full output table to a csv eventually, but I have yet to include that in my code.
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)
.csvfiles in the proper format so we can try to reproduce your problem?req(input$file1, input$file2)todata<-reactive({, since that can't run without both. 2) Load each file in a separatereactive, then merge them in a 3rdreactive. 3) renamedatasince it clashes with the built indata()function (unlikely to be the problem, but it's good practice)