Click on URL reloading the Dashbaord

Hi
I create a variable with a link
urlLink1 <- a("R Community", href="https://forum.posit.co/")
i put this variable urlLink1 inside text string and on click, the site opens, no issue in opening the URL.
But the problem is R Dashboard gets reloaded and gets initialized. Is there any solution to stop R to reload, but to just open the URL on browser

thanks

Does it help if you open the link in a new browser tab by specifying target="_blank"?

urlLink1 <- a("R Community", href="https://forum.posit.co/", target="_blank")

sorry, no , it does not open the browser. just opens r like modal dialogue screen with blank

Kind Regards

What about as HTML?

shiny::HTML("<a href = 'https://forum.posit.co\',  target = \'_blank\'>R Community</a>")

sorry, same problem, opening a blank window. please check from your side. if it works then there must be something wrong in my setup
could you please check and confirm

Thanks

Can you provide some example code that demonstrates the issue?

Thanks Scott, sorry for the delay. here is the example code that demonstrates the issue

library(shiny)
library(ggplot2)

urlinfluencediagnostic <- a("URL Link: Thanks to Bookdown.org for the valuable contribution on Doing Meta-Analysis in R:",
                            href = "https://bookdown.org/MathiasHarrer/Doing_Meta_Analysis_in_R/heterogeneity.html?q=%20Influence%20Analysis#influence-analysis"
)

ui <- fluidPage(
  column(
    width = 10,
    offset = 1,
    align='center',
    tags$br(),
    HTML("When you click the button, you will get the plot, but then when you click the url Link, the dashboard gets reloaded, the plot goes off "),
    tags$br(),
    actionButton(inputId = 'mGetMePlot',label = "Get me the Plot"),
    plotOutput(outputId = 'mmtcarsPlot',width = '100%',height = '400px'),
    tags$br(),
    urlinfluencediagnostic
    
  )
)

server <- function(input, output, session) {
  data(mtcars, package="datasets")
  observeEvent(input$mGetMePlot,{
    output$mmtcarsPlot <- renderPlot({
      ggplot(mtcars, aes(x=hp, y=mpg, color=cyl )) +
        geom_point(size=3)
    })
  })

}

shinyApp(ui, server)

Thanks for the code. When I run the code as-is using "Run External", I can generate the plot, and then when I click the link , I am taken to the website. When I hit the back button, I come back to the app and the plot is reset as you describe.

However, adding the statement target = "_blank" to the url (see below), I can generate the plot, and now when I click the link, a new window is launched and the app is left unchanged (plot still shows).

urlinfluencediagnostic <- a("URL Link: Thanks to Bookdown.org for the valuable contribution on Doing Meta-Analysis in R:",
                            href = "https://bookdown.org/MathiasHarrer/Doing_Meta_Analysis_in_R/heterogeneity.html?q=%20Influence%20Analysis#influence-analysis",
                            target = "_blank"
                            )

I ran the original code using "Run in Window" and "Run in Viewer Pane" and never experienced the app resetting after clicking the link. The only time it did for me was in the scenario I described above (i.e. using the back button to get back to the app in "Run External"). I hope this helps.

Thanks Scott,
sorry I am not getting it right. I get a blank new window, when i click the link, plot is not disturbed.
probably there must of some setting gone wrong in my Rstudio.

Assuming you are using RStudio, when you click the arrow to the right of Run App, are you selecting the "Run External" option?

image

my settings are like this
image
is this ok

Yes, it’s fine to run like that. However, out of curiosity, does the app behave as expected if you select “Run External” and then run the app?

Wow, resolved, Thanks Scott
after making "Run External" and by adding target = "_blank" as you suggested, first the shiny app opens in browser and click on the URL link opens up next tab with the web site. your perseverance is very much appreciated

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.