0

Hello and thanks for reading me. I am working on a small app that shows a table in shiny with the "reactable" library, but I would like to obtain a reactive value when I click on a certain cell, with which I can get a text output type "paste0("you chose" , value0)", but so far I haven't found a correct way to do it. Does anyone have any idea how to do that

The actual code im using is:

shinyApp(
  
  ui = fluidPage(
    reactableOutput("tabla")
  ),
  server = function(input, output){
    
    output$tabla <- renderReactable({
      
      iris |> 
        reactable(
          columns = list(
            
            Species = colDef(cell = function(value) {
              htmltools::tags$a(href = value, target = "_blank", value)
            })
          )
        )
      
      
    })
    
  }
  
)

1 Answers1

0
library(shiny)
library(reactable)
shinyApp(
    
    ui = fluidPage(
        reactableOutput("tabla"),
        verbatimTextOutput("selected")
    ),
    server = function(input, output){
        
        output$tabla <- renderReactable({
            iris |> 
                reactable(
                    columns = list(
                        Species = colDef(cell = function(value) {
                            htmltools::tags$a(href = value, target = "_blank", value)
                        })
                    ),
                    selection = "single", onClick = "select"
                )
        })
        
        value0 <- reactive({
            getReactableState("tabla", "selected")
        })
        output$selected <- renderPrint({
            req(value0())
            print(paste("you chose" , value0()))
        })
    }

)

enter image description here

Read more here

lz100
  • 6,990
  • 6
  • 29