å¼€å‘选择/å–消选择所有按钮以获得闪亮效果

时间:2015-02-09 21:43:47

标签: r shiny

çµæ„Ÿæ¥è‡ªsolution我åªæ˜¯æƒ³çŸ¥é“是å¦å¯ä»¥å›žåˆ°æŒ‰é’®ï¼†ï¼ƒ34; All"å–消选中所有列å称åŽã€‚当然,我å¯ä»¥ç®€å•åœ°å¼€å‘else if函数:

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

并且结果计算diamondsæ•°æ®é›†ä¸­çš„所有列,但在radioButtonsé¢æ¿ä¸­æ²¡æœ‰ä»»ä½•å˜åŒ–(å³ï¼†ï¼ƒ34;手动选择"按钮ä»å°†æ‰“开)。相å,我想在å–消选中所有checkboxGroupInput选项åŽè‡ªåŠ¨æ›´æ”¹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 (使用我的其他功能):

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]
})
})

3 个答案:

答案 0 :(得分:1)

也许您正在寻找更新å•é€‰æŒ‰é’®çš„方法 http://shiny.rstudio.com/reference/shiny/latest/updateRadioButtons.html

答案 1 :(得分:0)

æ„Ÿè°¢Rohit Das我是我想åšçš„。

我的æ„æ€æ˜¯ï¼Œ

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]
 }

})

答案 2 :(得分:0)

shinyWidgets库有一个很好的函数å«pickerInput(),附带一个“全选/å–消全选â€åŠŸèƒ½ã€‚ç»è¿‡å¤§é‡ç ”究,我å‘现这是唯一内置此功能的Shiny输入:

enter image description here

链接到网站:https://dreamrs.github.io/shinyWidgets/index.html