0

I have created a shiny app, deployed it on my server, and embedded it within an iFrame on another website. In the shiny app, I have some really basic HTML links that users can click to find out more information on things within the shiny app.

E.g. <a href='url' target='_blank'>More Info</a>

When viewing the embedded app, clicking will open the new link within the iframe. Instead, I would like for users to be able to click the link and have their whole browser window be redirected.

I'm more familiar with R but pretty new to creating websites, so any suggestions would be appreciated, either on changes within the shiny app or on the website side where the app is embedded.

ismirsehregal
  • 30,045
  • 5
  • 31
  • 78
mishyrose
  • 1
  • 4

1 Answers1

0

Welcome to stackoverflow!

As mentioned here you can add <base target="_parent"> to the head of the page in the iframe to open the links in the parent window or <base target="_blank"> to open them in a new window.

Here is a shiny example:

library(shiny)

if(!dir.exists("myhtmlcontent")){
  dir.create("myhtmlcontent")
}

writeLines(text = '<!DOCTYPE html>
<html>
<head>
<title></title>
<base target="_blank">
</head>
<body>
<a href="https://www.r-bloggers.com/">Visit r-bloggers.com</a>
</body>
</html>', "myhtmlcontent/iframe_content.html")

addResourcePath("myhtmlcontent", "myhtmlcontent")

ui <- fluidPage(
  # tags$head(tags$base(target="_blank")), # to be used when showing this shiny app in an iframe
  tags$iframe(src="myhtmlcontent/iframe_content.html", height = 600, width = 600)
)

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

shinyApp(ui, server)
ismirsehregal
  • 30,045
  • 5
  • 31
  • 78