This slightly modified version of your code seems to work. All I did was change the data input from reading files to explicitly constructing the data frames. I put action buttons on the side bar to trigger the creation of the data frames. The download throws an error and I did not investigate that. Do you agree that the merge works?
library(shiny)
ui<-fluidPage(
titlePanel(title="Mi aplicación"),
sidebarLayout(
sidebarPanel(
actionButton("fileA", label = "Cargue aqui su archivo Nro. 1 en formato txt"),
actionButton("fileB", label = "Cargue aqui su archivo Nro. 2 en formato txt")
),
mainPanel(
tabsetPanel(type="tab" ,
tabPanel ("Data 1" ,
tableOutput(outputId="tablita1")),
tabPanel("Data 2" ,
tableOutput(outputId = "tablita2")),
tabPanel("Unión de las datas" ,
fluidRow(
column(4,uiOutput("seleccione_col1"))
,
column(4,
uiOutput("seleccione_col2"))
,
column(4,
downloadButton("downloadData", "Decargar"))
))),
tableOutput(outputId = "tablitaMerge"))
))
server<-function(input,output){
dataA <- eventReactive(input$fileA,{
data.frame(Men = c("Bob", "Steve", "Steve", "Bob", "Bob"),
Women = c("Mary", "Mary", "Sue", "Mary", "Sue"),
Value = 1:5)
})
output$tablita1 <- renderTable({
if(is.null(dataA())){return()}
dataA()
}, type = "html", bordered = TRUE, align = "c", width = 5)
dataB <- eventReactive(input$fileB,{
data.frame(Men = c("Bob", "Steve", "Bob", "Steve", "Bob"),
Women = c("Mary", "Sue", "Sue", "Mary", "Mary"),
Value = 11:15)
})
output$tablita2 <- renderTable({
if(is.null(dataB())){return()}
h=dataB()
}, type = "html", bordered = TRUE, align = "c", width = 5)
output$seleccione_col1 <- renderUI({
seleccion <- names(dataA())
selectInput(inputId="columnsA", (("Seleccione la columna")),
choices = seleccion,
selected = seleccion[1])
})
output$seleccione_col2 <- renderUI({
seleccion <- names(dataB())
selectInput(inputId="columnsB", (("Seleccione la columna")),
choices = seleccion,
selected = seleccion[1])
})
output$tablitaMerge<- renderTable({
A=as.character(input$columnsA)
B=as.character(input$columnsB)
j=merge(dataA(),dataB(),by.x=A,
by.y=B,all.x=TRUE) #
})
#https://shiny.rstudio.com/articles/download.html
output$downloadData <- downloadHandler(
filename = function() {
paste(input$dataset, ".csv", sep = "")
},
content = function(file) {
write.csv(datasetInput(), file, row.names = FALSE)
}
)
}
shinyApp(ui=ui,server=server)