我是闪亮仪表板的新手。我想在上传的不同数据集中动态选择数据集,并使用它来显示数据集。
我写了下面的代码,但是我收到了错误,
警告:DT :: datatable中的错误:'data'必须是二维的(例如数据框或矩阵)
UI
ui <- dashboardPage(skin = "yellow",
dashboardHeader(title = "Analytics Workbench 2.0", titleWidth = 250,
dropdownMenuOutput("msgs")),
dashboardSidebar(
sidebarMenu(
fileInput("Table1", "Train Data"),
fileInput("Table2", "Test Data"),
menuItem("Variable Analysis", icon = icon("edit"),
menuSubItem("Uni-Variate Analysis"),
menuSubItem("Multi-Variate Analysis"))
)
),
dashboardBody(
fluidPage(
fluidRow(
column(12, box(title = "Train Data", width = 6, solidHeader = TRUE, status = "primary",
collapsible = TRUE, DT::DTOutput("dtable1")),
box(title = "Test Data", width = 6, solidHeader = TRUE, status = "primary",
collapsible = TRUE, DT::DTOutput("dtable2")))),
fluidRow(
column(12, box(title = "Structure", width = 6, solidHeader = TRUE, status = "primary",
collapsible = TRUE, verbatimTextOutput("str1")),
box(title = "Structure", width = 6, solidHeader = TRUE, status = "primary",
collapsible = TRUE, verbatimTextOutput("str2"))))
)
)
)
服务器
server <- function(input, output) {
Train <- reactive({
if (is.null(input$Table1)) return(NULL)
read.table(input$Table1$datapath, fill = TRUE, header=T, sep=",", na.strings = c(""," ",NA))
})
Test <- reactive({
if (is.null(input$Table2)) return(NULL)
read.table(input$Table2$datapath, fill = TRUE, header=T, sep=",", na.strings = c(""," ",NA))
})
dataset_1 <- reactive({
switch(input$Datasets,
"Train" = Train,
"Test" = Test)
})
output$dtable2 <- DT::renderDT({
DT::datatable(dataset_1(), options = list(scrollX = TRUE))
}) }
请帮我解决这个问题。
谢谢Balaji