How To Open Links in New Tab with Shiny app in R

Viewed 295

I have a shiny app and I use this HTML Code to render some youtube links now I want it to open in new tab when I click the image. I am confused about using " or ' and where to put target="_blank" to open these links in new tab please some good soul guide me and where to put target="_blank"

Thanks in advance

ui <- navbarPage("[GOWNDY]",#theme = shinytheme("cosmo"),
                 useShinyjs(),             
                 tabPanel("Regional",
                          titlePanel("Regional Vids"),
                          textOutput("regvideost") %>% 
                            tagAppendAttributes(class = 'date'),
                          #actionButton("vidbtn", "Refresh"),
                          #actionButton("test", "Test"),
                          #selectInput("sortinput", "Sort:",c("Descending" = "desc","Ascending" = "asc")),
                          hr(),
                          uiOutput("vids"),
                          
                 ),                                  
          
)

server <- function(input,output,session) {

  output$vids <- renderUI({
    videos <- readRDS(file ="videos.Rda")
    lapply(1:length(videos), function(i) {
      HTML(paste0('<a href="',videos[[i]]$url,'"><img loading="lazy" src="',
                  'https://img.youtube.com/vi/',videos[[i]]$id,'/hqdefault.jpg',
                  '" alt="',videos[[i]]$id,'" style="width:100%;"></a>','<h3>',
                  "Views: ",as.integer(videos[[i]][["views_count"]])," Likes: ",
                  as.integer(videos[[i]][["statistics"]][["likeCount"]])," VPH : ",
                  as.integer(videos[[i]]$vph),'</h3>','<h2>',videos[[i]]$title,'</h2>',
                  '<hr style="width:100%;height:10px;border-width:0;color:gray;background-color:gray">'))
    })
  })
}


shinyApp(ui = ui, server = server)
0 Answers
Related