如何解决闪亮的 R 通过单击/按钮选择一组项目
我想知道是否有一种方法可以使用 pickerInput 或 selectInput 或类似的方法(理想情况下)或像全选(或者)这样的按钮通过单击从列表中选择多个项目。例如,我想通过单击从 100 多个国家/地区中选择 20 个国家/地区的预定义列表。在下面的代码中,这基本上就像单击一次选择“USA”、“CAN”和“SYR”一样。
我遇到过类似的问题,例如here 表明这种组选择是可能的。但是,我很难理解它,并且还想知道是否有更简单的方法来实现这种组/多选。
任何帮助将不胜感激。
谢谢
library(shiny)
library(dplyr)
library(tidyverse)
df = data.frame("Country" = c("USA","USA","CAN","AFG","SYR","SYR"),"Year" = c(2000,2001,2000,2001),"Variable_1" = c(10,12,14,16,10,11,13),"Variable_2" = c(20,19,18,17,20,21,22,23),"Variable_3" = c(13,13,12))
#df_long <- melt(df,id=c("Country","Year"))
ui = fluidPage(
titlePanel("My Dashboard"),pickerInput("myvariable","Pick variables",choices =c("Variable_1","Variable_2","Variable_3"),options =list("actions-Box" = TRUE),multiple=TRUE,selected = "Variable_1"),sliderInput("year_selector","Select Year Range",min = 2000,max = 2003,value = c(2000,2013)),pickerInput("choicePicker","Pick countries",choices =c("USA","CAN"),selected="SYR"),plotOutput("trend")
)
server = function(input,output,session){
selected <- reactive(filter(df,Country %in% input$choicePicker,Year>=input$year_selector[1],Year<=input$year_selector[2]))
output$trend = renderPlot({
ggplot(selected(),aes_string(x="Year",y=input$myvariable,color="Country",group="Country")) +
geom_line(size = 2) +
scale_x_continuous(breaks = pretty_breaks()) +
labs(x = "",y = paste0(input$myvariable),title = paste(","," "),caption = paste(" "," ")) +
theme(legend.position = c(0.8,0.8))
})
}
shinyApp(ui=ui,server=server)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。