Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
Using both Select extension and server-side selection of rows in shiny app with datatable

I've been working on some R shiny app that allows users to browse some data. It is displayed in a table and I want this table to have two functionalities:

  • It should allow user to select rows from the table manually by clicking and using buttons to select all and deselect all.
  • It should allow user to select rows from the table by using some queries (not filtering it! -- unselected rows should still be displayed).

These functionalities are supposed to work simultaneously -- e.g. user may query the table by providing some conditions, select all rows fulfilling them by using some button and then add more rows to the selection by clicking them manually.

The first functionality can be easily obtained using Select extension for DT -- and it works perfectly well.

The second functionality can be implemented by taking some input from the user and selecting appropriate rows by using dataTableProxy objects and selectRows function on the server side -- and it works perfectly well.

The problem arises when I try combining them. I know that it is not advisable, console displays warnings when mixing them, but it just seemed the fastest solution for me.

Here is some simplified code:

library(shiny)
library(DT)

ui <- fluidPage(
  dataTableOutput("my_table"),
  actionButton("my_button", "Select some rows")
)


server <- function(input, output, session) {
  data(iris)
  
  output[["my_table"]] <- renderDataTable(
    iris,
#    extensions = c("Select", "Buttons"),
#    options = list(
#      dom = 'Brtip',
#      buttons = c("selectAll", "selectNone"),
##      select = list(style = "multi+shift", items = "row")
#    ),
#    server = FALSE,
##    selection = "none"
  )
  
  proxy <- dataTableProxy("my_table")
  
  observeEvent(input[["my_button"]], {
    proxy %>% selectRows(1:5)
  })
}

shinyApp(ui, server)

Lines that are commented out turn on selection buttons and replace default built-in selection for DT with selection API implemented in Select extension -- as a result making proxy selection on server side impossible. I can leave those double-commented lines commented and it seems to work, but only at a glance. In reality default selection of shiny "loses" with extension selection, which can be proven by the fact that even though some rows are displayed as selected, "Deselect all" button is inactive.

My question is: what is the easiest way to combine those two approaches? Is there any option for "Select" extension I am missing that would enable selection by shiny proxy? I could solve it by manually implementing some callbacks for table instead of using proxy, but it seems like a lot of work and I would be grateful for any suggestion how to avoid it.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda