Debbie Oomen
Debbie Oomen

Reputation: 333

Add link to external URL in sidebarmenu dashboard

Hope you can help me out. Is there any way to add a hyperlink in the sidebarmenu of shiny dashboard? I tried it using the following code:


ui <- dashboardPage(

  dashboardHeader(title = "Co-Lock App"),
  dashboardSidebar(
    sidebarMenu(
      id = "tabs",
      menuItem("Manual", tabName = 'manual', icon = icon("book-reader")),
      menuItem("Tumor Cell Expression", tabName =  "known", icon = icon("check-double")),
      menuItem("Immune Cell Expression", tabName = "immune", icon = icon("check-double")),
      menuItem("Tumor Cell Targets", tabName = "target", icon = icon("bullseye")),
      menuItem("Immune Cell Targets", tabName = "immunetarget", icon = icon("bullseye")),
      menuItem("Perfect Match", tabName = "match", icon = icon("heart")),
      menuItem(uiOutput("png"))
    )
  ),
  dashboardBody())

server <- function(input, output, session){

  output$png <- renderUI({
    tags$a(img(src = "ccle.png"), href = "https://www.ebi.ac.uk/gxa/experiments/E-MTAB-2770/Results", target = "_blank")
  })

}

shinyApp(ui = ui, server = server)

While the link works, the png image is huge and when I try adjusting the width and height, nothing changes. Is there anyway around this?

Thank you!

Upvotes: 1

Views: 567

Answers (1)

BSCowboy
BSCowboy

Reputation: 357

Older question, but I thought I would share a solution with minimal code change.

Solution: add width = "50px" inside the image tag. You may need to play with sizing to get it right.

I don't have the image in the code above, so I tried this with my own image and it worked. Here's the original code with the proposed solution:

ui <- dashboardPage(

  dashboardHeader(title = "Co-Lock App"),
  dashboardSidebar(
    sidebarMenu(
      id = "tabs",
      menuItem("Manual", tabName = 'manual', icon = icon("book-reader")),
      menuItem("Tumor Cell Expression", tabName =  "known", icon = icon("check-double")),
      menuItem("Immune Cell Expression", tabName = "immune", icon = icon("check-double")),
      menuItem("Tumor Cell Targets", tabName = "target", icon = icon("bullseye")),
      menuItem("Immune Cell Targets", tabName = "immunetarget", icon = icon("bullseye")),
      menuItem("Perfect Match", tabName = "match", icon = icon("heart")),
      menuItem(uiOutput("png"))
    )
  ),
  dashboardBody())

server <- function(input, output, session){

  output$png <- renderUI({
    tags$a(img(src = "ccle.png", width = "20px"), href = "https://www.ebi.ac.uk/gxa/experiments/E-MTAB-2770/Results", target = "_blank")
  })

}

shinyApp(ui = ui, server = server)

Upvotes: 1

Related Questions