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

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

内容简介:翻译自: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


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

查看所有标签

猜你喜欢:

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

RESTful Web Services Cookbook

RESTful Web Services Cookbook

Subbu Allamaraju / Yahoo Press / 2010-3-11 / USD 39.99

While the REST design philosophy has captured the imagination of web and enterprise developers alike, using this approach to develop real web services is no picnic. This cookbook includes more than 10......一起来看看 《RESTful Web Services Cookbook》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具