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!
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 ) ) )