创建 link 到 Shiny 应用程序的另一部分

Create link to the other part of the Shiny app

我想知道是否可以为 Shiny 应用程序的其他部分创建一个 link。我的意思是,我有一页报告,其中包含 IntroductionPlot 1Plot 2 面板。在 Introduction 面板中,我想添加对 Plot 1Plot 2 面板的引用,以便在单击 link 后立即查看此图。有可能吗?

ui.R

library(shiny)

shinyUI(
  fluidPage(
  fluidPage(
    titlePanel("Introduction"),
    column(12,
    p("Lorem ipsum dolor sit amet, consectetur adipisicing elit. Proin
      nibh augue, suscipit a, scelerisque sed, lacinia in, mi. Cras vel
      lorem. Etiam pellentesque aliquet tellus. Phasellus pharetra nulla
      ac diam. Quisque semper justo at risus. Donec venenatis, turpis vel
      hendrerit interdum, dui ligula ultricies purus, sed posuere libero 
      dui id orci. Nam congue, pede vitae dapibus aliquet, elit magna 
      vulputate arcu, vel tempus metus leo non est. Etiam sit amet lectus
      quis est congue mollis. Phasellus congue lacus eget neque. Phasellus
      ornare, ante vitae consectetuer consequat, purus sapien ultricies 
      dolor, et mollis pede metus eget nisi. Praesent sodales velit quis
      augue. Cras suscipit, urna at aliquam rhoncus, urna quam viverra nisi,
      in interdum massa nibh nec erat."))
    ),
  fluidPage(
  
  titlePanel("Hello Shiny!"),
  
  sidebarLayout(
    sidebarPanel(
      sliderInput("bins",
                  "Number of bins:",
                  min = 1,
                  max = 50,
                  value = 30)
    ),
    
    mainPanel(
      plotOutput("distPlot")
    )
  )
),
fluidPage(
  
  titlePanel("Hello Shiny!"),
  
  sidebarLayout(
    sidebarPanel(
      sliderInput("bins",
                  "Number of bins:",
                  min = 1,
                  max = 50,
                  value = 30)
    ),
    
    mainPanel(
      plotOutput("distPlot2")
    )
  )
))
)

server.R

library(shiny)

shinyServer(function(input, output) {
  output$distPlot <- renderPlot({
    x    <- faithful[, 2]  # Old Faithful Geyser data
    bins <- seq(min(x), max(x), length.out = input$bins + 1)
    
    hist(x, breaks = bins, col = 'darkgray', border = 'white')
  })
  output$distPlot2 <- renderPlot({
    x    <- faithful[, 2]  # Old Faithful Geyser data
    bins <- seq(min(x), max(x), length.out = input$bins + 1)
    
    hist(x, breaks = bins, col = 'darkgray', border = 'white')
  })
})

您要查找的是 HTML anchor tag。 例如,您可以使用以下方法为您的 distPlot2 创建一个锚点:

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

您可以将 # 之后的内容替换为 id 您想要跳转到的任何 HTML 元素。