简体   繁体   中英

How to get reactive values from a click on shiny?

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)
            })
          )
        )
      
      
    })
    
  }
  
)
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()))
        })
    }

)

在此处输入图像描述

Read more here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM