Display more than one url links in shiny interface

shiny
html

#1

...I have a dataframe consist of 100 samples. There are two column, one url link, second a name or a heading to the url link. I want to display all those headings in shiny interface. Clicking which leads the user to the respective link page. How can I do that? Please helpstrong text


#2

If your dataframe is called df and columns called url and heading this should work...

library(shiny)
library(DT)

df$link <- paste0("<a href='", df$url, "' target='_blank'>", df$heading, "</a>")

ui <- fluidPage(
  DT::dataTableOutput("table")
)

server <- function(input, output) {
  
  output$table <- DT::renderDataTable({
    DT::datatable(df[, "link", drop = FALSE], escape = FALSE)
  })
  
}

shinyApp(ui, server)

#4

Hey paul I exactly used the same code.

But its throwing a error 'data' must be 2-dimensional (e.g. data frame or matrix)


#5

sorry yes the df[, "link"] subset was converting the data frame to a character vector as there was only 1 column left. Adding drop = FALSE inside the square brackets will ensure it keeps the data frame class. I've updated the code above to include this.

thanks,
Paul


#6

Thanxxx a lot Paul Its working fine now