Home > Mobile >  How to place text in same line with an html tag in R shiny?
How to place text in same line with an html tag in R shiny?

Time:10-27

As shown in the below image, I'm trying to place a line of text in front of an info icon rendered using the popify() function in the shinyBS package. The code at the bottom works for the situation where there is no text in front of info icon and commented-out is one of my attempts to insert the text. Uncomment, run the code, and you'll see garbled output.

So how would one insert text in front of the icon? One option is to split the text and icon into 2 separate columns, but I don't want to fiddle with the column widths to make it look right. I want the text to "flow into" the icon.

I thought this Stack Overflow question might provide an answer but it is a dead end: enter image description here

Code:

library(shiny)
library(shinyBS)

app = shinyApp(
  ui =
    fluidPage(
      sidebarLayout(
        sidebarPanel(
          sliderInput("bins","Number of bins:",min = 1,max = 50,value = 30)
        ),
        mainPanel(
          plotOutput("distPlot"),
          uiOutput("uiExample")
        )
      )
    ),
  server =
    function(input, output, session) {
      output$distPlot <- renderPlot({
        x <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins   1)
        hist(x, breaks = bins, col = 'darkgray', border = 'white')
      })
      output$uiExample <- renderUI({
        # paste( #uncomment
          # "Look at the little circle >>", #uncomment
               tags$span(
                 popify(icon("info-circle", verify_fa = FALSE),
                        "Placeholder",
                        "This icon is <b>placeholder</b>. It will be fixed</em>!")
               )
        # ) #uncomment
      })
    }
)

runApp(app)

CodePudding user response:

This could be achieved via a tagList and another span:

library(shiny)
library(shinyBS)

app = shinyApp(
  ui =
    fluidPage(
      sidebarLayout(
        sidebarPanel(
          sliderInput("bins","Number of bins:",min = 1,max = 50,value = 30)
        ),
        mainPanel(
          plotOutput("distPlot"),
          uiOutput("uiExample")
        )
      )
    ),
  server =
    function(input, output, session) {
      output$distPlot <- renderPlot({
        x <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins   1)
        hist(x, breaks = bins, col = 'darkgray', border = 'white')
      })
      output$uiExample <- renderUI({
        tagList(
          tags$span(
            "Look at the little circle >>"
          ),
          tags$span(
            popify(icon("info-circle", verify_fa = FALSE),
                   "Placeholder",
                   "This icon is <b>placeholder</b>. It will be fixed</em>!")
          )  
        )
      })
    }
)

runApp(app)

enter image description here

  • Related