"Select All" 操作按钮不起作用
"Select All" action button doesn't work
我创建了两个操作按钮 Select All
和 Deselect All
。出于某种原因,Deselect All
有效,但 Select All
无效 。
这是为什么? Deselect All
按钮取消突出显示所有行,如我所料。但是,Select All
按钮没有任何作用。
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)
server.R
function(input, output, session) {
# Update summaryTable When users click 'Select All'
summaryTable <- eventReactive (input$selectAll,{
print("SelectAll")
DT::datatable(rawdata, selection = list(target = 'row', selected = c(1:ncol(rawdata()))))
})
# Update summaryTable When users click 'Deselect All'
summaryTable <- eventReactive (input$deselectAll,{
print("deselectAll")
DT::datatable(rawdata, selection = list(target = 'row', selected = c(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 {
summaryTable()
}
})
output$temp <- renderPrint({
print(input$selectAll)
print(input$deselectAll)
})
}
ui.R
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"))
)
)
)
这是你想要的吗?请注意,我将 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)
我创建了两个操作按钮 Select All
和 Deselect All
。出于某种原因,Deselect All
有效,但 Select All
无效 。
这是为什么? Deselect All
按钮取消突出显示所有行,如我所料。但是,Select All
按钮没有任何作用。
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)
server.R
function(input, output, session) {
# Update summaryTable When users click 'Select All'
summaryTable <- eventReactive (input$selectAll,{
print("SelectAll")
DT::datatable(rawdata, selection = list(target = 'row', selected = c(1:ncol(rawdata()))))
})
# Update summaryTable When users click 'Deselect All'
summaryTable <- eventReactive (input$deselectAll,{
print("deselectAll")
DT::datatable(rawdata, selection = list(target = 'row', selected = c(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 {
summaryTable()
}
})
output$temp <- renderPrint({
print(input$selectAll)
print(input$deselectAll)
})
}
ui.R
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"))
)
)
)
这是你想要的吗?请注意,我将 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)