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

142
Views
Cuente el número de clics en iframe implementado en shiny

Soy muy nuevo con iframes. Estoy tratando de implementar un código brillante para poder contar el número de páginas que visito cuando implemento un iframe de un periódico en línea. Entonces, quiero contar cuántas veces cambia el iframe al hacer clic.

Hasta ahora tengo:

 library(shiny) library(shinydashboard) ui <- dashboardPage( dashboardHeader(title = "Basic dashboard"), dashboardSidebar(), dashboardBody( fluidRow( box(width = 12, HTML(' <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> <style> iframe{ width: 100%; height: 600px; border: 2px solid #ccc; } </style> </head> <body> <script> var i =-1; </script> <iframe src="https://elpais.com/" onLoad="console.log(++i)"></iframe> </body>'), textOutput("view") ) ) ) ) server <- function(input, output) { output$view <- renderText( paste0( "User ID is: " ) ) } runApp(list(ui = ui, server = server), launch.browser = TRUE)

Cada vez que hago clic en un enlace, puedo ver el valor de la variable "i" en la consola de Google Chrome. Pero en realidad quiero tener acceso a este valor en mi código R. He visto que puedes acceder a las variables js con shiny usando shiny.oninputchange. Sin embargo, estoy muy confundido sobre cómo se debe implementar esto.

Gracias de antemano si puede responder a mis preguntas!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Quiero contar la cantidad de veces que hago clic en el iframe y la página del iframe se actualiza a una nueva (por ejemplo, una noticia diferente). ¡Espero que esta respuesta ayude!

about 4 years ago · Juan Pablo Isaza Report

0

Lo siento si la pregunta fue un poco confusa. Finalmente lo resolví así. Cada vez que se actualiza el iframe incrustado en mi aplicación brillante, tengo un conteo que agrega uno a su valor. De esta manera puedo contar el número de páginas que visito mientras navego en mi marco. Lo hago agregando uno al conteo cada vez que se actualiza la página en el Iframe.

 library(shiny) library(shinydashboard) ui <- dashboardPage( dashboardHeader(title = "Basic dashboard"), dashboardSidebar(), dashboardBody( fluidRow( box(width = 12, HTML('<input type="text" id="count" name="count" style="display: none;"> '), HTML(' <style> iframe{ width: 100%; height: 600px; border: 2px solid #ccc; } </style> </head> <body> <script> var countStr = "count"; var changeStr = "change"; var countInput = document.getElementById(countStr); countInput.value = -1; </script> <iframe src="https://elpais.com/" onLoad="var event = new Event(changeStr);countInput.value++;countInput.dispatchEvent(event)"></iframe> </body>'), #includeScript("example/get_user_id.js"), textOutput("view"), actionButton("submit", "Submit", class = "btn-primary"), ) ) ) ) server <- function(input, output) { count <- reactive({ input$count }) output$view <- renderText( paste0( "User ID is: ",count()) ) } runApp(list(ui = ui, server = server), launch.browser = TRUE)
about 4 years ago · Juan Pablo Isaza 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!