闪亮的 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 (将#修改为@)