I have a requirement to read 2 separate .CSV files in a single shiny page where i need to get the column data as per the selected column from drop down.
Using below code i managed to developed the R code as per the requirement , but it is only for one .csv file, but i need to have the second .csv file as well in the same page.
Tried using Fluidpage and fluidrow i didn't managed to get the desired output .
Could you please help me in this.
Thanks in advance.
below is the code:
library(shiny)
ui <- fluidPage(
h2('The uploaded file data'),
dataTableOutput('mytable'),
fileInput('file', 'Choose info-file to upload',
accept = c(
'text/csv',
'text/comma-separated-values',
'text/tab-separated-values',
'text/plain',
'.csv',
'.tsv'
)
),
Taken from: Shiny - File Upload
tags$hr(),
checkboxInput('header', 'Header', TRUE),
radioButtons('sep', 'Separator',
c(Comma=',',
Semicolon=';',
Tab='\t'),
','),
radioButtons('quote', 'Quote',
c(None='',
'Double Quote'='"',
'Single Quote'="'"),
'"'),
actionButton("choice", "incorporate external information"),
selectInput("columns", "Select Columns", choices = NULL), # no choices before uploading
column(dataTableOutput("table_display"),width=4)
)
server <- function(input, output, session) { # added session for updateSelectInput
info <- eventReactive(input$choice, {
inFile <- input$file
# Instead # if (is.null(inFile)) ... use "req"
req(inFile)
# Changes in read.table
f <- read.table(inFile$datapath, header = input$header, sep = input$sep, quote = input$quote)
vars <- names(f)
# Update select input immediately after clicking on the action button.
updateSelectInput(session, "columns","Select Columns", choices = vars)
f
})
output$table_display <- renderDataTable({
f <- info()
f <- subset(f, select = input$columns) #subsetting takes place here
f
})
}
shinyApp(ui, server)
Result =
expected output sholuld be like ==