I am trying to create an app in R
shiny
. The first thing I would like to do is select two csv files to display on a page. According to this: Creating tables in R shiny dynamically I need to add a dataTableOutput
for each table in the UI
and another renderDataTable
in my server
. However, the app doesn't work when I try to load multiple files. My code is below.
X <- c("plyr", "dplyr", "tm", "wordcloud", "SnowballC", "stringdist", "tidytext",
"rmarkdown", "knitr", "quanteda", "qdap", "reshape", "stringr", "RecordLinkage",
"data.table", "rvest", "shiny", "shinydashboard", "DT")
lapply(X, FUN = function(X){
do.call("library", list(X))
})
UI
ui <- dashboardPage(
dashboardHeader(title = "Record Linkage App"),
dashboardSidebar(
sidebarMenu(
## Tab 1 -- Specify Task
menuItem("Select Task And Upload Files", tabName = "task", icon = icon("file-text-o")),
## Tab 2 -- View Raw Data Files
menuItem("View Raw Data", tabName = "raw", icon = icon("file-text-o")),
## Tab 3 -- View Processed Data Files
menuItem("View Processed Data", tabName = "processed", icon = icon("file-text-o")),
## Tab 4 -- Select Training Set
menuItem("Select Training Set", tabName = "mltrain", icon = icon("file-text-o")),
## Tab 5 -- View Weight & Probabilities (choose which chart to view or both?)
menuItem("Visualize Distributions", tabName = "distributions", icon = icon("bar-chart-o")),
## Tab 6 -- View Results (review, match and trash files--need to be able to choose dataset)
## Want to be able to add checkboxes to select rows for inclusion in deletion later on
menuItem("View Result Files", tabName = "fileview", icon = icon("file-text-o"))
)), # close dashboard sidebar
#### Dashboard Body starts here
dashboardBody(
tabItems(
### Specify Task & Upload Files Tab
tabItem(tabName = "task",
radioButtons("task", "Select a Task:", c("Frame Deduplication", "Frame Record Linkage")),
fileInput("selection", "Upload Files:", multiple = T,
accept = c(".xls", "text/csv", "text/comma-separated-values, text/plain", ".csv")),
helpText(paste("Please upload a file. Supported file types are: .txt, .csv and .xls.")),
helpText(paste("Note: Record Linkage requires two data frames."))
), # close first tabItem
tabItem(tabName = "raw",
helpText(paste("This tab displays the raw, unprocessed data frames selected in the previous tab.")),
helpText(paste("Select the columns you wish to display. These columns will be used for string comparisons")),
dataTableOutput("contents"),
dataTableOutput("contents")
)
) # close tabItems
) # close dashboardBody
) #close dashboardpage
options(shiny.maxRequestSize = 100*1024^2)
SERVER
server <- function(input, output, session) {
output$contents <- renderDataTable({
req(input$selection)
#browser()
read.csv(input$selection$datapath)
})
output$contents <- renderDataTable({
req(input$selection)
#browser()
read.csv(input$selection$datapath)
})
}
shinyApp(ui, server)
My question is:
- what is the best way to load and display multiple data tables? I would like to continue with the dashboard layout above.
- Can someone explain why when I select multiple files nothing shows up on the "raw" tab?
Thanks for your help, I really appreciate it.