当我尝试更改侧边栏中的过滤器时,我收到错误:选择了未定义的列
我将此示例用于我的编码:sample
但我的编码有什么问题?改变colomns仍然有效。
server.r
library(shiny)
library(dplyr)
library(DT)
shinyServer(function(input, output)
{
output$table <- DT::renderDataTable(DT::datatable({
db2out <- db2
if (input$MetIDlist != "All") {
db2out <- db2out[db2out$Metric.ID == input$MetIDlist]
}
if (input$TClist != "All") {
db2out <- db2out[db2out$Technical.Criterion == input$TClist]
}
if (input$RTlist != "All") {
db2out <- db2out[db2out$RT.Snapshot.name == input$RTlist]
}
if (input$Objectlist != "All") {
db2out <- db2out[db2out$Object.type == input$Objectlist]
}
if (input$VioStlist != "All") {
db2out <- db2out[db2out$Violation.status == input$VioStlist]
}
if (input$Critlist != "All") {
db2out <- db2out[db2out$Critical.Y.N == input$Critlist]
}
if (input$Grouplist != "All") {
db2out <- db2out[db2out$Grouping == input$Grouplist]
}
db2out[, input$show_vars, drop = FALSE]
}))
})
ui.r
library(shiny)
shinyUI(fluidPage
(
titlePanel("Dashboard"),
sidebarLayout(
sidebarPanel(
selectInput("MetIDlist", "Metric.ID",
c("All",
sort(unique(as.character(db2$Metric.ID))))),
selectInput("TClist", "Technical Criterion",
c("All",
sort(unique(as.character(db2$Technical.Criterion))))),
selectInput("RTlist", "Release",
c("All",
sort(unique(as.character(db2$RT.Snapshot.name))))),
selectInput("Objectlist", "Objects",
c("All",
sort(unique(as.character(db2$Object.type))))),
selectInput("VioStlist", "Violation Status",
c("All",
sort(unique(as.character(db2$Violation.status))))),
selectInput("Critlist", "Critical",
c("All",
sort(unique(as.character(db2$Critical.Y.N))))),
selectInput("Grouplist", "Group",
c("All",
sort(unique(as.character(db2$Grouping))))),
conditionalPanel(condition="db2",
selectizeInput("show_vars", "Spalten",
names(db2), selected = names(db2), multiple = TRUE)),
width = 2),
mainPanel(
tabsetPanel(
tabPanel("List", dataTableOutput("table")),
tabPanel("Summary")
)
)
)
))
我的数据库db2如下所示:
'data.frame': 5303 obs. of 9 variables:
$ Metric.ID : num 7156 7220 7220 7220 7220 ...
$ Metric.Name : Factor w/ 99 levels "Avoid accessing data by using the position and length",..: 51 59 59
$ Technical.Criterion: Factor w/ 25 levels "Architecture - Multi-Layers and Data Access",..: 4 9 9 9 9 9 9 9 9 9 ...
$ RT.Snapshot.name : Factor w/ 1 level "2017_RT12": 1 1 1 1 1 1 1 1 1 1 ...
$ Violation.status : Factor w/ 2 levels "Added","Deleted": 2 1 2 2 2 1 1 1 1 1 ...
$ Critical.Y.N : num 0 0 0 0 0 0 0 0 0 0 ...
$ Grouping : Factor w/ 29 levels "281","Bes",..: 27 6 6 6 6 7 7 7 7 7 ...
$ Object.type : Factor w/ 11 levels "Cobol Program",..: 8 7 7 7 7 7 7 7 7 7 ...
$ Object.name : Factor w/ 3771 levels "[S:\\SOURCES\\",..: 3771 3770 3769 3768 3767 3
有人能给我一份工作解决方案或提示的样本吗?
由于
答案 0 :(得分:0)
看起来当你进行子集化时,你试图从列中进行选择。在方括号前面需要逗号。
e.g。
db2out <- db2out[db2out$Metric.ID == input$MetIDlist]
变为
db2out <- db2out[db2out$Metric.ID == input$MetIDlist,]
这样你就可以从行而不是列中进行选择
答案 1 :(得分:0)
它有效
最后我更改了ui.r
中的selecitzeinput语句selectizeInput('e2', 'Auswahl', selected = names(db2), choices = names(db2), multiple = TRUE),
和我server.r中的最后一个语句
db2out[, input$e2, drop = FALSE]