R 开发“全选/取消全选”按钮,用于

R 开发“全选/取消全选”按钮,用于,r,shiny,R,Shiny,受此启发,我只是想知道,在取消选中所有列名称后,是否有可能返回到按钮“全部”。当然,如果函数: if(input$radio == "All"){ hw } else if (length(input$show_vars) == 0){ hw } else { hw[,input$show_vars,drop=FALSE] } library(shiny) library(ggplot2) data(diamonds) hw <- diamonds shinyServer

受此启发,我只是想知道,在取消选中所有列名称后,是否有可能返回到按钮“全部”。当然,如果函数:

if(input$radio == "All"){
  hw
} 
else if (length(input$show_vars) == 0){
  hw
}
else {
  hw[,input$show_vars,drop=FALSE]
}
library(shiny)
library(ggplot2)
data(diamonds)
hw <- diamonds

shinyServer(function(input, output) {

Data <- reactive({

if(input$radio == "All"){
  hw
} 
else if (length(input$show_vars) == 0){
  hw
}
else {
  hw[,input$show_vars,drop=FALSE]
}

})

output$summary <- renderPrint({
 ## dataset <- hw[, input$show_vars, drop = FALSE]
 dataset <- Data()
 summary(dataset)
})

# a large table, reative to input$show_vars
output$mytable1 <- renderDataTable({
 Data()
 ## hw[, input$show_vars, drop = FALSE]
})
})
结果统计
菱形数据集中的所有列,但在radioButtons面板中没有任何变化(即,“手动选择”按钮仍将打开)。相反,我想在取消选中所有复选框GroupInput选项后自动更改radioButton

ui.R

library(shiny)

shinyUI(fluidPage(
 title = 'Examples of DataTables',
  sidebarLayout(
   sidebarPanel(

   radioButtons(
    inputId="radio",
    label="Variable Selection Type:",
    choices=list(
      "All",
      "Manual Select"
    ),
    selected="All"),

    conditionalPanel(
     condition = "input.radio != 'All'",
      checkboxGroupInput(
      'show_vars', 
      'Columns in diamonds to show:',
      choices=names(hw), 
      selected = "carat"
    )
   )

  ),
 mainPanel(
  verbatimTextOutput("summary"), 
  tabsetPanel(
    id = 'dataset',
    tabPanel('hw', dataTableOutput('mytable1'))
  )
 )
)
))
server.R(带有我的附加else if功能):

库(闪亮)
图书馆(GG2)
数据(钻石)

hw也许您正在寻找更新单选按钮的方法
多亏了罗希特·达斯,我才如愿以偿

我是说

data(diamonds)
hw <- diamonds

shinyServer(function(input, output,session) {

Data <- reactive({

 if(input$radio == "All"){
  hw

 } 
 else if (length(input$show_vars) == 0){
  updateRadioButtons(session,
                       "radio", 
                       "Variable Selection Type:",
                       choices=list("All","Manual Select"),
                       selected = "All")
  updateCheckboxGroupInput(session, 
                           'show_vars', 
                           'Columns in diamonds to  show:',
                           choices=names(hw), 
                           selected = "carat")
 }

 else {
  hw[,input$show_vars,drop=FALSE]
 }
数据(菱形)

hwshinyWidgets
库有一个很好的函数,名为
pickerInput()
,它带有“全选/全选”功能。经过大量研究,我发现这是唯一具有内置功能的闪亮输入:


链接到站点:

很高兴它有所帮助。顺便问一下,为什么要使用c()将updateRadioButtons和updateCheckboxGroupInput放在向量中。我想你可以省略c()部分,它们会一个接一个地被执行。当然,在那个例子中,中间的逗号就去掉了。好吧,我就这么做了。再次感谢:)!