Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create link to the other part of the Shiny app

Tags:

r

shiny

I wonder if it is possible to create a link to other part of Shiny app. I mean, I have one page report with Introduction, Plot 1 and Plot 2 panel. Within Introduction Panel I would like to add a reference to Plot 1 and Plot 2 Panel in order to see this plot immadiately, after clicking 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')
  })
})
like image 560
Nicolabo Avatar asked Feb 19 '15 11:02

Nicolabo


1 Answers

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.

like image 126
NicE Avatar answered Oct 17 '22 03:10

NicE