通过单击选中所有复选框的

通过单击选中所有复选框的

本文介绍了R SHINY CheckboxGroupInput-通过单击选中所有复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含checkboxGroupInput的R闪亮应用程序,我正在尝试使用updateCheckboxGroupInput函数创建一个"全选"按钮。您可以看到下面的完整代码,但基本上我是这样定义CB组的:

checkboxGroupInput("campaigns","Choose campaign(s):",campaigns_list)

然后单击按钮,调用函数:

updateCheckboxGroupInput(session,"campaigns","Choose campaign(s):",choices=campaigns_list,selected=campaigns_list)

我有一个指示,该函数已运行,但它实际上执行的是取消选中复选框的操作。顺便说一句,当我在定义cbGroupInput时将Selected放入时,它确实起作用了,但在函数上不起作用。

谢谢!

这是我的服务器。R:

library(shiny)
source('usefulFunctions.R')
shinyServer(function(input, output, session) {

  output$cascading <- renderUI({
    provider_id <- input$provider
    if (provider_id == "") return(NULL)
    campaigns_list <<- t(getCampaigns(provider_id))
    tagList(
      checkboxGroupInput("campaigns","Choose campaign(s):",
                         choices = campaigns_list, selected = campaigns_list),
      actionLink("selectall","Select All")
      )
  })

  observe({
    if(is.null(input$selectall)) return(NULL)
    if (input$selectall > 0)
    {
      print(campaigns_list)
      updateCheckboxGroupInput(session,"campaigns","Choose campaign(s):",choices=campaigns_list,selected=campaigns_list)
    }
    })


})

推荐答案

我还在此处添加了选择和取消选择选项,方法是检查按钮或链接是否可以被2整除

#rm(list = ls())
library(shiny)
campaigns_list <- letters[1:10]

ui =fluidPage(
  checkboxGroupInput("campaigns","Choose campaign(s):",campaigns_list),
  actionLink("selectall","Select All")
)
server = function(input, output, session) {

  observe({
    if(input$selectall == 0) return(NULL)
    else if (input$selectall%%2 == 0)
    {
      updateCheckboxGroupInput(session,"campaigns","Choose campaign(s):",choices=campaigns_list)
    }
    else
    {
      updateCheckboxGroupInput(session,"campaigns","Choose campaign(s):",choices=campaigns_list,selected=campaigns_list)
    }
  })
}
runApp(list(ui = ui, server = server))

这篇关于R SHINY CheckboxGroupInput-通过单击选中所有复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 04:03