I have the following example app (code below). The idea is that if a user selects the second column (index of 1), the selection goes to the third column (index of 2), as I don't want the user to be able to select the second column at all (as far as I know there is no built-in way to stop the user selecting a particular column in DT).
The issue is that while selectRows(tableProxy, c(2)
works (a trivial example of a row selection), selectColumns(tableProxy, c(2))
only deselects the currently selected column and does not select the third column.
Is there an issue with my syntax, or is this a bug? If it is a bug, is there a workaround?
Reproducable example:
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
fluidRow(
tags$div(title = "Iris table",
DT::dataTableOutput("irisTable"))
)
)
# Define server logic required to draw a table
server <- function(input, output) {
output$irisTable <- DT::renderDT(datatable(head(iris, 20), options = list(paging = FALSE, searching = FALSE),
rownames = FALSE,
selection = list(target = 'row+column', mode='single', selected = list(rows = c(NULL), cols = c(2)))
) %>%
formatStyle(0, target= 'row',color = 'black',
lineHeight='70%', padding = '3px 3px', fontSize = '80%')
)
tableProxy <- dataTableProxy("irisTable")
observeEvent(input$irisTable_columns_selected, {
if (input$irisTable_columns_selected == 1) {
#tableProxy %>% selectColumns(2)
selectRows(tableProxy, c(2))
selectColumns(tableProxy, c(2))
}
})
}
# Run the application
shinyApp(ui = ui, server = server)
Update: I have tried the above with the example code published here (converted to work with a single file Shiny app), and I have the same issue. I've reinstalled the DT package and it doesn't resolve the issue.
It's a bug of DT that should have been fixed via the PR rstudio/DT#528 . You can install the dev version to test it by calling devtools::install_github("rstudio/DT")
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.