Create Link to the Other Part of the Shiny App

Create link to the other part of the Shiny app

What you are looking for is an HTML anchor tag.
You could for example create an anchor to your distPlot2 using:

column(12,p(HTML("intro text <a href='#distPlot2'>Go to plot 2</a> intro text ")))

You can replace what is after the # by the id any HTML element you want to jump to.

Internal link between tabs to specific section in R Shiny app

Using K. Rohde's answer as starting point, their JavaScript was extended by a second argument for the given id and a command, that scrolls to it (document.getElementById(anchorName).scrollIntoView()), allows to move to a certain section within a given tabPanel after switching to it.

library(shiny)

ui = shinyUI(
navbarPage("Header",
tabPanel("Home",
tags$head(tags$script(HTML('
var fakeClick = function(tabName, anchorName) {
var dropdownList = document.getElementsByTagName("a");
for (var i = 0; i < dropdownList.length; i++) {
var link = dropdownList[i];
if(link.getAttribute("data-value") == tabName) {
link.click();
document.getElementById(anchorName).scrollIntoView({
behavior: "smooth"
});
};
}
};
'))),
fluidPage(
span("bring me to end of tab2",
onclick = "fakeClick('Tab2', 'visitme')"))),
tabPanel("Tab2",
"Some Text inside Tab 2.",
div("This is a long div to visualize the redirection",
style = "background-color: gray;
height: 1000px;
width: 100px;"),
div(id = "visitme",
"This is the part where the redirection shall land."),
div("Another long div",
style = "background-color: gray;
height: 1000px;
width: 100px;"))))

server = function(input, output, session){}

runApp(shinyApp(ui, server), launch.browser = TRUE)

Create URL hyperlink in R Shiny?

By using paste, you're treating the url as a string. The function you want to use here is tagList:

runApp(
list(ui = fluidPage(
uiOutput("tab")
),
server = function(input, output, session){
url <- a("Google Homepage", href="https://www.google.com/")
output$tab <- renderUI({
tagList("URL link:", url)
})
})
)

Externally link to specific tabPanel in Shiny App

You could add a search query parameter to the URL (eg. href='www.myapp.com?tab=tab2), and in the app that is being linked you would have to add a bit of logic that changes to a specified tab on initialization if the search string is present (eg. look at session$clientData$url_search and if it exists and there's a tab variable, then use updateTabsetPanel() to go to that tab)

R shiny build links between apps

Amending my earlier response, (because, agreed, a simpler solution should be available)

Instead, here's a solution built on mining the session object:

if you open the second shiny app via

<a href="http://server.com/app2?Species=setosa">

(change server.com/app2 to your actual link)
then in that second app, include this for the select object:

EDIT: Note, since this relies on the session object, your server function will change from function(input,output) to function(input,output,session)

ui.R:

htmlOutput('selectSpecies')

server.R:

output$selectSpecies <- renderUI({
URLvars <- session$clientData$url_search
# NOTE: the following regex is not one-size-fits-all
# if you use multiple inputs, you'll probably need to adjust it
# also remove special characters, because I want to sanitize our inputs

Species <- gsub('[[:punct:]]','',URLvars)
Species <- sub('^.*Species(.*$)','\\1',URLvars)

selectInput("select", label=h3("Iris Type"), choices=list('setosa', 'versicolor', 'virginica'),
selected=ifelse(Species=="",'setosa',Species), multiple=FALSE)
})

So the session object does contain the portion of the url it was opened with, so it's just a matter of converting that info to a variable we can use.

Linking to a tab or panel of a shiny app

We have just released a routing library, which makes linking in Shiny easy. Here's how it looks like in a nutshell.

make_router(
route("<your_app_url>/main", main_page_shiny_ui),
route("<your_app_url>/other", other_page_shiny_ui)
)

More information can be found in this blog post.

How to create a variable hyperlink in an R Shiny App

Your problem is that renderText doesn't just have text as output but rather a complete html object. In this case you want to use renderUI for the complete a object. And let the href be dynamicly generated within this. Like this

library(shiny)
library(shinydashboard)
ui <- fluidPage(title = "App Title",
dashboardPage(title = "App Title",
header = dashboardHeader(tags$li(uiOutput("page"), class = "dropdown")),
sidebar = dashboardSidebar(sidebarMenu(id = "tabs",
menuItem(text = 'Tab 1', tabName = 'tab1'),
menuItem(text = 'Tab 2', tabName = 'tab2'),
menuItem(text = 'Tab 3', tabName = 'tab3')
)
),
body = dashboardBody(div())
)
)
server <- function(input, output, session) {
output$page <- renderUI({
a(href = paste0(
'Help_File.html',
if(input$tabs == 'tab1') {'#page_1'}
else if (input$tabs == 'tab2') {'#page_2'}
else if (input$tabs == 'tab3') {'#page_3'}
else ''),
target="_blank",
style = "color:#FFF;",
icon("question"),
title = "Help",
"Help")
})
}

shinyApp(ui,server)

Hope this helps!

How to create a single line of text with hyperlink or other elements on same line in R Shiny?

You just need a comma. If you want your link also formatted with the h4 style, the code would look like this:

library(shiny)

shinyApp(
ui = fluidPage(
fluidRow(
h4("We recently launced a new initiative. For more information visit: ", a("Search for it", href = "wwww.google.com"))
)
),
server = function(input, output) {

}
)

Which results in:

Sample Image



Related Topics



Leave a reply



Submit