WiseChirag
WiseChirag

Reputation: 307

How to format/align text in shiny bsPopover?

I am new to Shiny r and trying to build an app. I am using bspopover to display a popover over a slider input. The text in the popover is split in multiple lines like pointers (see below)

i. This is line 1

ii.This is line 2

iii. This is line 3

I have stored these 3 lines in a variable (see below)

CR1_BS<-paste("i. This is line 1",
      "ii. This is line 2",
      "iii. This is line 3")

And then using the bspopover like

bsPopover(id="CR1_S1",title="x",content=strsplit(CR1_BS, "\n")[[1]] ,"right",options = list(container = "body"))

In the popover is currently displayed as plain text without different lines like "i. This is line 1","ii. This is line 2","iii. This is line 3"

Where as i need the output to be something like below

i. This is line 1

ii. This is line 2

iii. This is line 3

I have searched thru the site and other internet resources but not yet able to find a solution. Your help is really appreciated.

Upvotes: 0

Views: 1266

Answers (1)

SBista
SBista

Reputation: 7694

This can be done using a little <br> which is line break in javascript.

Here is a sample code:

library(shiny)
library(shinyBS)

CR1_BS<-paste("i. This is line 1",
              "ii. This is line 2",
              "iii. This is line 3", sep = "<br>")


ui <- fluidPage(
  actionButton("CR1_S1", "Button"),

  bsPopover(id="CR1_S1",title="x",content=CR1_BS ,"right",options = list(container = "body"))
)

server <- function(input, output){}

shinyApp(ui, server)

With this you get an app with a popover and line break like this: enter image description here

Hope it helps!

Upvotes: 2

Related Questions