Links not converting into hyperlink

I am trying to print the sites and their link as a hyperlink but not getting the desired output.

dt<- data.frame("Site"=c("google", "facebook", "microsoft"), 
               "links"=c("https://www.google.co.in/", "https://www.facebook.com/", "https://www.microsoft.com/en-in"))

ui<- fluidPage(
              titlePanel("Links"),
               fluidRow(column( width = 8,
                                div(
                                          tableOutput("t1"), inlineCSS(list("table" = "font-size: 15x; width: 40%")),
                                          
                                )
               )))

server<- function(input,output,session)
{
  output$t1<- renderTable({
    paste(dt$Site, dt$links)
  })
  
}
shinyApp(ui,server)

You will need to add html <a> tags around the hyperlinks.

My code is somewhat like this- I want to take an output from the select input and show only the "site and it's link. Ex- If I select google from selectInput, then output should be-
o/p
Site Link
Google https://www.google.co.in/(can be clicked)

dt<- data.frame("Site"=c("google", "facebook", "microsoft"), 
                "links"=c("https://www.google.co.in/", "https://www.facebook.com/", "https://www.microsoft.com/en-in"))

ui<- fluidPage(
  titlePanel("Links"),
  fluidRow(column( width = 8,
                   div(
                     tableOutput("t1"), inlineCSS(list("table" = "font-size: 15x; width: 40%")),
                      actionButton("send", "Send")
                   )
  )))

server<- function(input,output,session)
{
  
  observeEvent(input$send,{
    insertUI(selector = "#send", where = "beforeBegin",
             ui=div(class="bubbles",
                    div(class="bubble",
                        wellPanel(
                          p("What is your preferred site?", tags$br(),
                            selectInput("selection", "site", choices =sort(unique(as.character(dt$Site) ))
                            )
                          )))))
    
  })
  
  observeEvent(input$selection, {
  output$t1<- renderTable({
    paste0("<a href='",dt$links,"</a>")
  })
  })
  
}
shinyApp(ui,server)

It's working but it is showing the output of all selectInput. I want the site and link of only the selected input. Currently, the output is thsi--

Are you familiar with the tidyverse package?
Add a filter()

Yes, I do. In my main program I have put up the links in a reactive function. Like this-

link_diploma<- reactive({
    li<-d_course() %>% filter(`Discipline Category1`== input$diploma_courses) %>% 
      filter(Subject1 == diploma_spec()) %>% pull(`Program Website`)
    li<- data.frame(li)
    names(li)[1]<- "Links"
    li<- li%>% head(5)
    return(li)
  })```

I am then using reactive function in the solution you provided.
output$t1 <- shiny::renderDataTable({
                                     enframe(paste0("<a href='",**link_diploma()**,"'>",**link_diploma()**,"</a>"),value="link",name=NULL)
                                   }, escape=FALSE,
                                   options = list(dom = 't',
                                                  searching= FALSE))
                                                                        
                                                     ))))
})
  
Tell me where I am going wrong.?

the asterix's are for emphasis and not in your code I hope ?
what sort of an object is link_diploma() is it character vector that needs enframing to make into a data.frame as in your original example ?
I'm thinking not, as link_diploma reactive is a data.frame(li) with head applied on it.
You can't enframe a data.frame, its already framed...

  1. Yes, the * is not in my code.

  2. link_diploma is the reactive function for links of diploma education. Yes, it is character.
    let me break this-
    d_course- is the reactive dataframe of all types of education with their links.
    discipline Category1- type of Discipline(like- Arts, science, Computers)
    input$diploma_courses- the selected diploma course from selectInput.
    Subject1- Type of subjects in the discipline(Ex- For Arts discipline, Subject1- Arts and
    Humanities, Arts and cultures, Heritage)
    diploma_Spec- it's the selected Input of subject1
    Program site- the website for the programs we have selected after the filtration.
    li- is th variable to store within the reactive function, so that I can return it easily.
    head(5)- to return the only top 5 websites of the Programs.

  3. I made it a dataframe so that I can add operations in it easily if needed furthermore, I can remove it too.

choose between passing a character vector of links as your reactive, which the other function will enframe.
or else prepare the data.frame in the reactive and dont enframe it a second time.
There is no singular correct way to do it, its up to you. but you need to be consistent in your approach. good luck.

Thanks Nir. Solution got implemented.:slight_smile: :slight_smile: :slightly_smiling_face:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

Hi! I don't want to use renderdata table. cz I have no use of paging, search bar,. I just want the links to be published with the site but clickable.

Such features can be disabled

1 Like

You can turn off all those things on datatable.

In any case, you don't need to use datatable, just those <a> tags.

2 Likes
library(shiny)
library(shinyjs)
dt<- data.frame("Site"=c("google", "facebook", "microsoft"), 
                "links"=c("https://www.google.co.in/", "https://www.facebook.com/", "https://www.microsoft.com/en-in"))

ui<- fluidPage(
  titlePanel("Links"),
  fluidRow(column( width = 8,
                   div(
                     shiny::dataTableOutput("t1"), inlineCSS(list("table" = "font-size: 15x; width: 40%")),
                     actionButton("send", "Send")
                   )
  )))

server<- function(input,output,session)
{
  
  observeEvent(input$send,{
    insertUI(selector = "#send", where = "beforeBegin",
             ui=div(class="bubbles",
                    div(class="bubble",
                        wellPanel(
                          p("What is your preferred site?", tags$br(),
                            selectInput("selection", "site", choices =sort(unique(as.character(dt$Site) ))
                            )
                          )))))
    
  })
  
  observeEvent(input$selection, {
    output$t1 <- shiny::renderDataTable({
     enframe(paste0("<a href='",dt$links,"'>",dt$links,"</a>"),value="link",name=NULL)
    }, escape=FALSE,
    options = list(dom = 't',
                   searching= FALSE))
  })
  
}
shinyApp(ui,server)
1 Like