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

356
Visualizações
R-Shiny - Create radio buttons in tables with columns as selectable

I'm trying to build in Shiny a table that uses radio buttons. I need the layout to be column specific(Instead of row specific which the example uses). I was following the code example here: https://rstudio.github.io/DT/011-radio.html. It appears to be working except I can't get the results to show in the output window.

library(shiny)
library(DT)

c1 = "This is comment 1"
c2 = "This is comment 2"
c3 = "This is comment 3"
c4 = "This is comment 4"
c5 = "This is comment 5"
comments = list(c1,c2,c3,c4,c5)

ui <- fluidPage(
    tags$head(tags$style(HTML("#foo.tr.selected {background-color:red}"))),
    title = 'Radio buttons in a table',
    DT::dataTableOutput('foo'),
    verbatimTextOutput('sel')
)


  server <- function(input, output) {
    m = matrix(
      as.character(1:5), nrow = 5, ncol = 1, byrow = FALSE,
      dimnames = list(comments, LETTERS[1])
    )
    for (i in seq_len(nrow(m))) {
      m[i, ] = sprintf(
        '<input type="radio" name="%s" value="%s"/>',
        "AValue", m[i, ]
      )
    }
    m
    output$foo = DT::renderDataTable(
      m, escape = FALSE, selection = 'none', server = FALSE,
      options = list(dom = 't', paging = FALSE, ordering = FALSE),
      callback = JS("table.cols().every(function(i, tab, col) {
          var $this = $(this.node());
          $this.attr('id', this.data());
          $this.addClass('shiny-input-radiogroup');
        });
        Shiny.unbindAll(table.table().node());
        Shiny.bindAll(table.table().node());")
    )
    output$sel = renderPrint({
      str(sapply(comments, function(i) input[[i]]))
    })
  }

shinyApp(ui = ui, server = server)

I'm assuming that my callback Javascript code has an error in it. I tried some different variations in the code but I can't get the results from the radio button. Thanks!

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