Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R &引用;选择全部";操作按钮没有';行不通_R_Shiny_Shiny Reactivity - Fatal编程技术网

R &引用;选择全部";操作按钮没有';行不通

R &引用;选择全部";操作按钮没有';行不通,r,shiny,shiny-reactivity,R,Shiny,Shiny Reactivity,我创建了两个操作按钮全选和全选。由于某些原因,取消选择所有起作用,但选择所有不起作用 为什么呢?取消选择所有按钮按预期取消所有行的高亮显示。但是,全选按钮不起任何作用 input$selectAll和input$deselectAll已正确更新(如TEMP选项卡所示) 有人能帮忙吗?这是我的密码。谢谢 数据集: colA <- c('A','B','C','D','E') colB <- c(1,2,3,4,5) rawdata <- as.data.frame(cbind(c

我创建了两个操作按钮
全选
全选
。由于某些原因,
取消选择所有
起作用,但
选择所有
不起作用

为什么呢?
取消选择所有
按钮按预期取消所有行的高亮显示。但是,
全选按钮不起任何作用

input$selectAll
input$deselectAll
已正确更新(如
TEMP
选项卡所示)

有人能帮忙吗?这是我的密码。谢谢

数据集:

colA <- c('A','B','C','D','E')
colB <- c(1,2,3,4,5)
rawdata <- as.data.frame(cbind(colA,colB))
View(rawdata)

这是你想要的吗?请注意,我将
ncol
更改为
nrow
,因为SelecteAll适合于行

library(shiny)
colA <- c('A','B','C','D','E')
colB <- c(1,2,3,4,5)
rawdata <- as.data.frame(cbind(colA,colB))

ui <- fluidPage(
  mainPanel(
    tabsetPanel(id = "allResults",
                tabPanel(value='inputVars',title='Variable Selection', 
                         verticalLayout(
                           DT::dataTableOutput('inputVars'),
                           br(),
                           fluidRow(align="bottom", 
                                    column(2, actionButton("selectAll"  , strong("Select All"))),
                                    column(3, actionButton("deselectAll", strong("Deselect All")))
                           )
                         )
                ),
                tabPanel(value='temp',title="TEMP", verbatimTextOutput("temp"))
    )
  )
)

server <- function(input, output, session) {

  var <- reactiveValues()
  observeEvent(input$selectAll,{
    print("SelectAll")
    var$selected <- 1:nrow(rawdata)
  })

  observeEvent(input$deselectAll,{
    print("deselectAll")
    var$selected <- 0
  })

  # Default SummaryTable
  output$inputVars <- DT::renderDataTable({
    if (input$selectAll==0 & input$deselectAll==0) {
      print("Default")
      DT::datatable(rawdata, options = list(paging = FALSE, searching = FALSE))
    } 
    else {
      DT::datatable(rawdata, selection = list(target = 'row', selected = var$selected))
    }
  })
}

shinyApp(ui = ui, server = server)
库(闪亮)

可乐这就是你想要的吗?请注意,我将
ncol
更改为
nrow
,因为SelecteAll适合于行

library(shiny)
colA <- c('A','B','C','D','E')
colB <- c(1,2,3,4,5)
rawdata <- as.data.frame(cbind(colA,colB))

ui <- fluidPage(
  mainPanel(
    tabsetPanel(id = "allResults",
                tabPanel(value='inputVars',title='Variable Selection', 
                         verticalLayout(
                           DT::dataTableOutput('inputVars'),
                           br(),
                           fluidRow(align="bottom", 
                                    column(2, actionButton("selectAll"  , strong("Select All"))),
                                    column(3, actionButton("deselectAll", strong("Deselect All")))
                           )
                         )
                ),
                tabPanel(value='temp',title="TEMP", verbatimTextOutput("temp"))
    )
  )
)

server <- function(input, output, session) {

  var <- reactiveValues()
  observeEvent(input$selectAll,{
    print("SelectAll")
    var$selected <- 1:nrow(rawdata)
  })

  observeEvent(input$deselectAll,{
    print("deselectAll")
    var$selected <- 0
  })

  # Default SummaryTable
  output$inputVars <- DT::renderDataTable({
    if (input$selectAll==0 & input$deselectAll==0) {
      print("Default")
      DT::datatable(rawdata, options = list(paging = FALSE, searching = FALSE))
    } 
    else {
      DT::datatable(rawdata, selection = list(target = 'row', selected = var$selected))
    }
  })
}

shinyApp(ui = ui, server = server)
库(闪亮)

是否要选择列或行?是否要选择列或行?
library(shiny)
colA <- c('A','B','C','D','E')
colB <- c(1,2,3,4,5)
rawdata <- as.data.frame(cbind(colA,colB))

ui <- fluidPage(
  mainPanel(
    tabsetPanel(id = "allResults",
                tabPanel(value='inputVars',title='Variable Selection', 
                         verticalLayout(
                           DT::dataTableOutput('inputVars'),
                           br(),
                           fluidRow(align="bottom", 
                                    column(2, actionButton("selectAll"  , strong("Select All"))),
                                    column(3, actionButton("deselectAll", strong("Deselect All")))
                           )
                         )
                ),
                tabPanel(value='temp',title="TEMP", verbatimTextOutput("temp"))
    )
  )
)

server <- function(input, output, session) {

  var <- reactiveValues()
  observeEvent(input$selectAll,{
    print("SelectAll")
    var$selected <- 1:nrow(rawdata)
  })

  observeEvent(input$deselectAll,{
    print("deselectAll")
    var$selected <- 0
  })

  # Default SummaryTable
  output$inputVars <- DT::renderDataTable({
    if (input$selectAll==0 & input$deselectAll==0) {
      print("Default")
      DT::datatable(rawdata, options = list(paging = FALSE, searching = FALSE))
    } 
    else {
      DT::datatable(rawdata, selection = list(target = 'row', selected = var$selected))
    }
  })
}

shinyApp(ui = ui, server = server)