0
私はデータフレームbook3を持っています。それは、3つの列、地域、国と格付けを持っています。従属選択によるプロット
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)
は私がドロップダウン「米州」領域から選択したときに達成したい、それだけでメキシコを表示する必要があると私はアジア太平洋地域を選択すると、それは中国とインドが表示されるはずですし、EMEAのために、それはドイツとスペインが表示されます。
簡単に言えば、地域と国の従属ドロップダウンを作成したいと思います。国のドロップダウンでは、地域に基づいて国が表示されます。
それは評価欄
に基づいて、同様のプロットを生成することができるはず私はui.Rとserver.Rで私のコードを持っている何か
を提案してください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))
})
})
ありがとうございます。 BarPlotでの選択に基づいて平均評価が表示されるはずです。私はbarplot関数を使ってbook3 $ ratingを使用しましたが、それはプロットしません。 –
平均評価:あなたは国ごとに1つの観察しかありませんか? –
これは私のために働いています: 'barplot(book3 [book3 $ country == input $ data2]、] $ Rating、ylim = c(0,10))'。 –