I have a data frame book3. It has three column Region, Country and Rating.
Region<- c("Americas", "Asia Pacific","Asia Pacific", "EMEA", "EMEA")
Country<- c("Mexico", "China","India", "Germany", "Spain" )
Rating<- c(5,3,3,2,4)
book3<- data.frame(Region, Country, Rating)
I want to achieve when i select from drop-down "Americas" Region, it should only display Mexico and when i select Asia Pacific it should display China and India and for EMEA it should display Germany and Spain.
In brief I want to create dependent drop down of Region and Country. The Country drop down should display the country based on the Region.
It should be able to generate the plot as well based on the rating column
I have my code in ui.R and server.R please suggest something
Ui.R
library(shiny)
ui <- fluidPage(
titlePanel("Test Dashboard "),
sidebarLayout(
sidebarPanel(
uiOutput("data1"), ## uiOutput - gets the UI from the server
uiOutput("data2")
),
mainPanel()
))
server.R
library(shiny)
shinyServer(function(input, output, session) {
Region<- c("Americas", "Asia Pacific","Asia Pacific", "EMEA", "EMEA")
Country<- c("Mexico", "China","India", "Germany", "Spain" )
Rating<- c(5,3,3,2,4)
book3<- data.frame(Region, Country, Rating, stringsAsFactors = F)
output$data1 <- renderUI({
selectInput("data1", "Select Region", choices = c(book3$Region))
})
output$data2 <- renderUI({
selectInput("data2", "select Country", choices = c(book3$Country))
})
})