Search code examples
shinyhyperlinkwhitespace

Why is my hyperlinked text in another line?


output$abstractText <- renderUI({
tags$div(
   HTML(
      paste("",
            "<span style='font-size: 30px; "Text",
            "",  
            "This tool has been developed by the ",
            tags$a(href = "https://www.","hyperlinked text"),
            ". For news and updates, follow us on Twitter ", 
            tags$a(href = "https://twitter.com", "@xyz"),
            "",

From "This tool..." on it appears in 4 lines - how can I have it in one line only?


Solution

  • Difficult to say without your full code, but the following example illustrates how you can do that.

    You most likely won't need paste and no need to mark the elements with HTML as htmltools will properly render the content. Furthermore, you barely need to create HTML tags by strings ("<span href=...") but you can (and should) simply use the wrappers from library htmltools (which is automatically loaded when loading shiny).

    Having said that, the following snippet shows that all the text is properly in one line:

    library(shiny)
    
    ui <- fluidPage(uiOutput("link"))
    
    server <- function(input, output, session) {
       output$link <- renderUI({
          div(
             span(
                style = "font-size: 30px",
                "Text",
                tags$a(
                   href = "https://www.google.com",
                   "Hyperlink Text"
                ),
                "For news and updates, follow us on ",
                tags$a(
                   href = "https://twitter.com", 
                   "Twitter"
                ) 
             )
          )
       })
    }
    
    shinyApp(ui, server)
    

    Screenshot of the rendered shiny output showing that the content is in one line as intended by the OP