我想包括在一個閃亮的應用程序應該繪製圖形複選框。 我的問題似乎很簡單,但我一直無法自己解決:(儘管有多個CheckboxGroupInput問題在StackOverflow或R幫助工具...checkboxGroupInput在R閃存ggplot使用
所以,我有一個科學研究,包括8篇散文命名爲1到8)和5個控制文章(命名爲PC1到PC5)。 我希望我的應用程序可以通過複選框詢問您想要查看的文章,並在同一圖形中繪製它們。 請注意我已經有一個你想這兩個變量看(2個顯卡),並且這工作就像一個魅力下拉菜單要價
這裏是我的用戶界面的簡化版本:
ui <- dashboardPage(
dashboardHeader(title="Test",
dropdownMenu(type = "notifications",
notificationItem(
text = "Verifier les points centraux",
icon = icon("exclamation-triangle"),
status = "warning"
)
)
),
dashboardSidebar(
sidebarMenu(
menuItem("Suivi par Variable", tabName = "SuiviVariable", icon =
icon("area-chart"))
)
),
dashboardBody(
# Suivi par Variable tab content
tabItem(tabName = "SuiviVariable",
h2("Graphique de Suivi pour Chaque Variable d'Intérêt"),
fluidRow(
box(title = "Choisir deux variables à comparer", status =
"info",br(),
selectInput("Variable1", label = "Variable 1",
choices = list_variables,
selected = list_variables[1]),
selectInput("Variable2", label = "Variable 2",
choices = list_variables,
selected = list_variables[1]),
checkboxGroupInput("Essais", "Essais à afficher :",c(1:8,"PC1", "PC2", "PC3", "PC4", "PC5")),
plotOutput("plot5", height = 600),
plotOutput("plot6", height = 600)
)
)
)
))
用戶界面部分似乎沒問題,因爲複選框顯示正確。
這裏是服務器的一部分:
server<-function(input, output){
output$plot5 <- renderPlot({
a<- as.vector(input$Essais)
dataTest <- as.data.frame(TrameTest[a,])
ggplot(data=dataTest, aes(x= N_ByEssai,y=dataTest[,input$Variable1], group= Nom, colour=Nom))+
geom_line()+
xlab("Duree de l'Essai")+
ylab(input$Variable1)
})
output$plot6 <- renderPlot({
dataTest <- as.data.frame(TrameTest[input$Essais,])
ggplot(data=dataTest, aes(x= N_ByEssai,y=dataTest[,input$Variable2],group= Nom, colour=Nom))+
geom_line()+
xlab("Duree de l'Essai")+
ylab(input$Variable2)
})}
在那裏,你可以看到我已經嘗試過使用輸入$ Essais,是徒勞的。 我讀過CheckboxGroupOutput返回一個字符矢量,我覺得它可能是我的問題,所以我試圖用as.vector來欺騙它,但它不會改變結果: 根據所選框的不同,我會得到一個空白的圖形或一個帶有圖例PC1/NA的圖形,以及一個僅在我無法識別的值的行(?!)。
你知道我爲什麼不能使用TrameTest [輸入$ Essais]作爲我的x值嗎?是因爲它不是矢量嗎? 你有沒有simle(我對R還不是很好)可以用作參考的CheckboxGroupInput的例子?
在此先感謝您的時間和想法
謝謝你的建議! – AUB