选择/取消选择所有按钮以选择闪亮变量

栏目: R语言 · 发布时间: 5年前

内容简介:翻译自:https://stackoverflow.com/questions/24916115/select-deselect-all-button-for-shiny-variable-selection

我有这个声明,让我得到关于我的变量的基本描述性统计数据:

checkboxGroupInput('show_vars', 'Columns in diamonds to show:',
                          names(input_data), selected = names(input_data))

但是,在不得不取消10个变量以获得我感兴趣的一个变量之后,我意识到这个用户界面不是很友好.我想添加一个按钮,在您单击它时选择/取消选择所有按钮.它可以多次点击.我甚至不确定如何开始.任何轻推都会有所帮助.

ui.R:

library(shiny)
hw<-diamonds 

shinyUI(fluidPage(
  title = 'Examples of DataTables',
  sidebarLayout(
    sidebarPanel(
        checkboxGroupInput('show_vars', 'Columns in diamonds to show:',
                           names(hw), selected = names(hw))

    ),
    mainPanel(
      verbatimTextOutput("summary"), 
      tabsetPanel(
        id = 'dataset',
        tabPanel('hw', dataTableOutput('mytable1'))
        )
    )
  )
))

server.R:

library(shiny)
data(diamonds)
hw<-diamonds  
shinyServer(function(input, output) {
  output$summary <- renderPrint({
    dataset <- hw[, input$show_vars, drop = FALSE]
    summary(dataset)
  })
  # a large table, reative to input$show_vars
  output$mytable1 <- renderDataTable({
    library(ggplot2)
    hw[, input$show_vars, drop = FALSE]
  })
})

我添加了一个global.R来加载包和数据 – 并不总是必要但它通常更干净.可能有不同的方法来完成我在下面所做的事情,但我倾向于在这种情况下使用条件面板.

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

library(shiny)
library(ggplot2)
##
shinyServer(function(input, output) {

  Data <- reactive({

    if(input$radio == "All"){
      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]
  })
})

global.R

library(shiny)
library(ggplot2)
data(diamonds)
hw <- diamonds

翻译自:https://stackoverflow.com/questions/24916115/select-deselect-all-button-for-shiny-variable-selection


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

CSS

CSS

David Sawyer McFarland / O'Reilly / 2006-08-24 / USD 34.99

Book Description Web site design has grown up. Unlike the old days, when designers cobbled together chunky HTML, bandwidth-hogging graphics, and a prayer to make their sites look good, Cascading St......一起来看看 《CSS》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

MD5 加密
MD5 加密

MD5 加密工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换