我正在努力建立一个记录链接应用在R发亮。我使用R已经有一段时间了,但是我还不太清楚。我的问题是,我正在努力弄清楚如何显示我通过fileInput上传的文件。我的密码在下面。
library(shiny)
library(shinydashboard)用户界面
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"))
), # close first tabItem
tabItem(tabName = "raw",
helpText(paste("This tab displays the raw, unprocessed data frames selected in the previous tab.")),
mainPanel(
tableOutput("contents")
)
) # close tabItems
) # close dashboardBody
) #close dashboardpage)
服务器
server <- function(input, output, session) {
output$contents <- renderTable({
req(input$file1)
read.csv(input$file1$datapath)
})
}
shinyApp(ui, server)我希望能够在标签"raw“中显示该表。
我的问题是: 1.如果我只想显示表,它需要是reactive吗?
input$file1$datapath如何进入renderTable如有任何建议或建议,将不胜感激。谢谢。
发布于 2019-04-05 22:52:37
我认为您对文档的理解有点过于严格了:您应该引用input$selection,而不是input$file1。我将您的服务器组件修改为此,它起了作用:
server <- function(input, output, session) {
output$contents <- renderTable({
req(input$selection)
read.csv(input$selection$datapath)
})
}顺便说一句:虽然没有伤害到任何东西,但你使用的是mainPanel,它通常与shiny::sidebarLayout一起使用在非仪表板应用中。但是,由于您使用的是shinydashboard,所以这是不必要的,您可以将最后一个tabItem减少到
tabItem(tabName = "raw",
helpText(paste("This tab displays the raw, unprocessed data frames selected in the previous tab.")),
tableOutput("contents")
)https://stackoverflow.com/questions/55543482
复制相似问题