在条形图中获取滤镜面板的值

时间:2016-07-04 12:32:56

标签: r shiny-server shiny shinydashboard

我在代码中创建了一个依赖列,关键要求是当用户选择过滤器选项时,它应该显示该选项的条形图。

根据我想要实现的代码。如果您运行我的代码并选择" Americas"在第一次下拉"地区"。第二次下降了墨西哥"并且第三次下拉有" HR"

当我编译代码时,它会显示两个条形图。我想比较"评级"的所有评级/值。和"评级1" (代码中的值字段),条形图中的所有值

字段的价值是"评级","评级1"

Ui.R

library(shiny)
ui <- fluidPage(
titlePanel(title = h2("Program Manager Dashboard ")),
sidebarLayout(
sidebarPanel(   
  uiOutput("data1"),   ## uiOutput - gets the UI from the server
 uiOutput("data2"),
 uiOutput("data3")
),
mainPanel(
  plotOutput("plot")
      )
  ))

Server.R

library(shiny)
shinyServer(function(input, output, session) {
Region<- c("Americas", "Asia Pacific","Asia Pacific", "EMEA", "EMEA","EMEA","Americas", "Americas")
  Country<- c("Mexico", "China","India", "Germany", "Spain","Spain","Mexico", "Mexico" )
  Function<-c("HR", "Finance", "IT","IT","IT","IT", "HR", "HR")
  Rating<- c(5,3,4,2,4,3, 1, 4)

  Rating1<- c(4,5,1,5,5,5,5, 4)
book3<- data.frame(Region, Country, Rating, Rating1,Function, stringsAsFactors = F)
output$data1 <- renderUI({
selectInput("data1", "Select Region", choices = c(book3$Region), selected = Region["Americas"] )
  })
output$data2 <- renderUI({
selectInput("data2", "select Country", choices = book3[which(book3$Region == input$data1),]$Country)
})
  output$data3<-renderUI({
   selectInput("data3", "Select Function", choices = book3[which(book3$Country==input$data2),]$Function)
})

barplot(book3$Rating,book3$Country==input$data2, ylim=c(0,5), xlim=c(0,2), width=0.2, col=c("darkblue","red"), xlab = "Customer Feedback")
  })
})

0 个答案:

没有答案