Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

148
Vistas
Count number of clicks in iframe implemented in shiny

i am very new with iframes. I am trying to implement a shiny code so that i can count the number pages I visit when implement an iframe from an online newspaper. So, i want to count how many time the iframe changes when clicking.

So far I have:

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)

Every time I click a link, I can see the value of variable "i" in the Google chrome console. But I actually want to have acces to this value in my R code. I have seen that you can acces js variables with shiny using shiny.oninputchange. Nevertheless I am very confused on how this should be implemented.

Thank you in advance if you can aswer my questions!

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I want to count the number of times I click on the iframe and the iframe page refreshes to a new one (for example, a diferent news item). I hope this answer helps!

about 4 years ago · Juan Pablo Isaza Denunciar

0

Sorry If the question was a little unclear. I finally solved it like this. Every time the iframe embedded in my shiny app refreshes I have a count that adds one to its value. This way I can count the number of pages I visit while navigating in my I frame. I do that by adding one to the count every time the page in the Iframe refreshes.

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda