Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

269
Vistas
¿Cómo diferenciar entre los botones en R/Shiny reactable javascript callback?

Tome este ejemplo de la documentación reaccionable (ejemplo brillante interactivo proporcionado en el enlace):

 data <- cbind( MASS::Cars93[1:5, c("Manufacturer", "Model", "Type", "Price")], details = NA ) reactable( data, columns = list( # Render a "show details" button in the last column of the table. # This button won't do anything by itself, but will trigger the custom # click action on the column. details = colDef( name = "", sortable = FALSE, cell = function() htmltools::tags$button("Show details") ) ), onClick = JS("function(rowInfo, colInfo) { // Only handle click events on the 'details' column if (colInfo.id !== 'details') { return } // Display an alert dialog with details for the row window.alert('Details for row ' + rowInfo.index + ':\\n' + JSON.stringify(rowInfo.row, null, 2)) // Send the click event to Shiny, which will be available in input$show_details // Note that the row index starts at 0 in JavaScript, so we add 1 if (window.Shiny) { Shiny.setInputValue('show_details', { index: rowInfo.index + 1 }, { priority: 'event' }) } }") )

Quiero incluir 2 botones por celda de columna de details , lo que puedo hacer cambiando la definición de cell a:

 cell = function() { a <- htmltools::tags$button("Approve") b <- htmltools::tags$button("Decline") return(list(a,b)) }

Pero entonces, ¿cómo diferenciar entre el botón Aprobar/Rechazar dentro de la función JS() onClick() ? ¿Hay otro parámetro que pueda pasar que me dé esta habilidad? console.log 'd tanto rowInfo como colInfo y no pude encontrar nada que pareciera útil para identificar los dos botones. Me gustaría tenerlo para poder devolver ambos:

Shiny.setInputValue('approve_button_click', ...)

y

Shiny.setInputValue('decline_button_click',...)

desde el lado JS para que pueda manejarlos por separado en R. ¡Cualquier ayuda es apreciada!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Si desea obtener solo el índice de fila, puede hacerlo:

 library(htmltools) details = colDef( name = "", sortable = FALSE, cell = function(value, rowIndex, colName){ as.character(tags$div( tags$button("Approve", onclick=sprintf('alert("approve - %d")', rowIndex)), tags$button("Decline", onclick=sprintf('alert("decline - %d")', rowIndex)) )) }, html = TRUE )

En brillante:

 reactable( data, columns = list( details = colDef( name = "", sortable = FALSE, cell = function(value, rowIndex, colName){ as.character(tags$div( tags$button( "Approve", onclick = sprintf( 'Shiny.setInputValue("approve", %d, {priority: "event"})', rowIndex ) ), tags$button( "Decline", onclick = sprintf( 'Shiny.setInputValue("decline", %d, {priority: "event"})', rowIndex ) ) )) }, html = TRUE ) ) )
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda