0

I have created a dependent column in my code, the critical requirement is when user select the filter option it should show the bar plot for the option.

As per the code I want to achieve following. If you run my code and select "Americas" in first drop down "Region". The second drop down has "Mexico" and and the third drop down has "HR"

When I compile the code it shows up two bar plot. I want to compare the all the ratings / values of "Rating" and "Rating1" (Value field in the code) with all the value in the bar plot

The Value of the fields are "Rating", "Rating1"

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")
  })
})
  • What is your question exactly? You have to many }) at the end of server.R, for example. And you should assign the barplot to an output, i.e., output$plot <- barplot( ... ) – Joris Gillis Jul 05 '16 at 09:24
  • I got the solution, I added this in output this code ..barplot((book3[which(book3$Functions == input$data3),]$Rating), ylim=c(0,5), xlim=c(0,2), width=0.5,col=c("darkblue")) – Rahul Thakur Jul 06 '16 at 09:01
  • I have another Question - How to print more than two values. In my code Rating field has the value, what if i add Rating1 and Rating2. how should be the output code. please run my code to get complete understanding – Rahul Thakur Jul 06 '16 at 09:04

0 Answers0