Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
462 views
in Technique[技术] by (71.8m points)

r - Create link to the other part of the Shiny app

I wonder if it is possible to create a link to other part of Shiny app. I mean, I have one page report with Itroductiion,Plot 1 and Plot 2 panel.Within Introduction Panel I would like to add a referent to Plot 1 and Plot 2 Panel in order to see this plot immadiately, after click the link. It is possible?

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')
  })
})
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...