Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
La técnica Js para capturar clics en una aplicación brillante no captura la identificación del nodo

Tengo la aplicación shiny a continuación en la que uso una técnica js para capturar clics en la aplicación sin tener que usar elementos de entrada brillantes. Funciona muy bien, pero no en los nodos, ya que quiero poder capturar nodos y obtener la ID del nodo.

La lógica es la siguiente: hago clic en el texto "Click me" o en los nodos y luego, en la consola de Rstudio, escribo input$js.node_clicked . El resultado debería ser "uno_1", que puedo aceptar porque "one" corresponde al nodo y "_1" al hacer clic en la secuencia. Pero cuando hago clic en los nodos, obtengo solo "_1" y no la identificación del nodo "one_1". La lógica es de aquí .

 library(shiny) library(shinyWidgets) library(DiagrammeR) library(magrittr) js <- ' $(document).on("click", ".node", function(e) { if(typeof BUTTON_CLICK_COUNT == "undefined") { BUTTON_CLICK_COUNT = 1; } else { BUTTON_CLICK_COUNT ++; } Shiny.onInputChange("js.node_clicked", e.target.id + "_" + BUTTON_CLICK_COUNT); }); ' ui <- fluidPage( tags$script(HTML(js)) , div(id="one","click me",class="node") , uiOutput("main") ) server <- function(input, output) { output$main <- renderUI({ tagList( div( grVizOutput("grr", width = "100%", height = "90vh") )) }) output$grr <- renderGrViz(grViz( "digraph test{ A[tooltip='A word']; B[tooltip='Another word']; A -> B;}" ) ) observeEvent(input$js.node_clicked , { browser() }) # } shinyApp(ui, server)
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Esto funciona así. Tienes que usar currentTarget en lugar de target . Evite incluir un punto en el nombre de entrada de Shiny.setInputValue (o Shiny.onInputChange , que es lo mismo), porque el punto tiene un significado especial.

 library(shiny) library(shinyWidgets) library(DiagrammeR) library(magrittr) js <- ' $(document).on("click", ".node", function(e) { if(typeof BUTTON_CLICK_COUNT === "undefined") { BUTTON_CLICK_COUNT = 1; } else { BUTTON_CLICK_COUNT++; } Shiny.setInputValue("js_node_clicked", e.currentTarget.id + "_" + BUTTON_CLICK_COUNT); }); ' ui <- fluidPage( tags$script(HTML(js)), div(id="one", "click me", class="node"), uiOutput("main") ) server <- function(input, output) { output$main <- renderUI({ tagList( div( grVizOutput("grr", width = "100%", height = "90vh") ) ) }) output$grr <- renderGrViz(grViz( "digraph test{ A[tooltip='A word']; B[tooltip='Another word']; A -> B;}" ) ) observeEvent(input$js_node_clicked , { print(input$js_node_clicked) }) } shinyApp(ui, server)
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!