Hello,
I'm a beginner with R and I have some questions about my first project.
I've got a database with following types of data in data.frame called db2:
'data.frame': 5303 obs. of 9 variables:
$ Metric.ID : num 7156 7220 7220 7220 7220 ...
$ Metric.Name : Factor w/ 99 levels "Avoid accessing",..: 51 59 59 59 59 59 59 59 59 59 ...
$ Technical.Criterion: Factor w/ 25 levels "Architecture",..: 4 9 9 9 9 9 9 9 9 9 ...
$ RT.Snapshot.name : Factor w/ 1 level "2017": 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 ": 27 6 6 6 6 7 7 7 7 7 ...
$ Object.type : Factor w/ 11 levels ",..: 8 7 7 7 7 7 7 7 7 7 ...
$ Object.name : Factor w/ 3771 levels
Now I want to make a simple UI to filter some rows and also can select columns to display with a default length of 10 rows.
In this moment I get following message: Warning: Error in [.data.frame: undefined columns selected
This is my ui.r
library(shiny)
shinyUI(fluidPage
(
titlePanel("Dashboard"),
sidebarLayout(
sidebarPanel(
selectInput("MetIDlist",
"Metric.ID",
c("All",
unique(as.character(db2$Metric.ID)))),
selectInput("TClist",
"Technical Criterion",
c("All",
unique(as.character(db2$Technical.Criterion)))),
selectInput("RTlist",
"Release",
c("All",
unique(as.character(db2$RT.Snapshot.name)))),
selectInput("Objectlist",
"Objects",
c("All",
unique(as.character(db2$Object.type)))),
selectInput("VioStlist",
"Violation Status",
c("All",
unique(as.character(db2$Violation.status)))),
selectInput("Critlist",
"Critical",
c("All",
unique(as.character(db2$Critical.Y.N)))),
selectInput("Grouplist",
"Group",
c("All",
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")
)
)
)
))
and this is my server.r
library(shiny)
library(dplyr)
library(stats)
library(DT)
shinyServer(function(input, output)
{
output$table <- DT::renderDataTable(DT::datatable({
data <- db2
if (input$MetIDlist != "All") {
data <- data[as.character(db2$Metric.ID) == input$MetIDlist]
}
if (input$TClist != "All") {
data <- data[as.character(data$Technical.Criterion) == input$TClist]
}
if (input$RTlist != "All") {
data <- data[as.character(data$RT.Snapshot.name) == input$RTlist]
}
if (input$Objectlist != "All") {
data <- data[as.character(data$Object.type) == input$Objectlist]
}
if (input$VioStlist != "All") {
data <- data[as.character(data$Violation.status) == input$VioStlist]
}
if (input$Critlist != "All") {
data <- data[as.character(data$Critical.Y.N) == input$Critlist]
}
if (input$Grouplist != "All") {
data <- data[as.character(data$Grouping) == input$Grouplist]
}
data
}))
})
# dataout <- data()
# dataout <- dataout[, input$show_vars, drop = FALSE]
#
# output$table <- DT::renderDataTable(data(), options=list(pageLength=10))
There are different ways to solve the problem. But I can't get the parts together for a simple solution.
Please help.
Thanks