0

that the last popover overwrites all others

I want to add multiple popovers on several ValueBoxes inside shinydashboard. I am using bsPopover() with unique id for each box. However, I am writing all my popovers in a helper file, and calling the source of this file inside my ui.r problem is, that the last popover overwrites everything, on the userInterface I can see only the last popover I added.

helper.r

bsPopover(
  id = "one", title = "ONE",
  content = "blah blah blah 1",
  trigger = "hover",
  placement = "right",
  options = list(container="body"))


bsPopover(
  id = "two", title = "TWO",
  content = "blah blah blah 2",
  trigger = "hover",
  placement = "right",
  options = list(container="body"))


bsPopover(
  id = "three", title = "THREE",
  content = "blah blah blah 3",
  trigger = "hover",
  placement = "bottom",
  options = list(container="body"))

ui.r

source("helper.r"),

1 Answers1

1

You'll have to wrap them in a list() for this to work:

library(shiny)
library(shinydashboard)
library(shinyBS)

writeLines(text = 'myPopovers = list(
  bsPopover(
  id = "one", title = "ONE",
  content = "blah blah blah 1",
  trigger = "hover",
  placement = "right",
  options = list(container="body")),
  bsPopover(
    id = "two", title = "TWO",
    content = "blah blah blah 2",
    trigger = "hover",
    placement = "right",
    options = list(container="body")),
  bsPopover(
    id = "three", title = "THREE",
    content = "blah blah blah 3",
    trigger = "hover",
    placement = "bottom",
    options = list(container="body"))
  )', con = "helper.R")

source("helper.R")

ui <- dashboardPage(
  dashboardHeader(title = "Value boxes"),
  dashboardSidebar(),
  dashboardBody(
    fluidRow(
      valueBoxOutput("one"),
      valueBoxOutput("two"),
      valueBoxOutput("three"),
      myPopovers
    )
  )
)

server <- function(input, output) {
  output$one <- renderValueBox({
    valueBox(
      "25%", "Progress", icon = icon("list"),
      color = "purple"
    )
  })

  output$two <- renderValueBox({
    valueBox(
      "80%", "Approval", icon = icon("thumbs-up", lib = "glyphicon"),
      color = "yellow"
    )
  })

  output$three <- renderValueBox({
    valueBox(
      "90%", "Approval", icon = icon("thumbs-up", lib = "glyphicon"),
      color = "green"
    )
  })
}

shinyApp(ui, server)

Result:

Result

ismirsehregal
  • 30,045
  • 5
  • 31
  • 78
  • Thank you so much, that helped me a lot, and the popovers work perfectly now. However, in the Ui i get a "FALSE FALSE" above the ValueBoxes in the dashboard as you can see in this screenshot: [Screenshot][1] [1]: https://i.stack.imgur.com/mjFAw.png – Jana Zuraik May 22 '19 at 12:20
  • Are you sure this is related to the valueBoxes? - Using my example it is not the case (added a screenshot) and it is hard to say without your UI code. – ismirsehregal May 22 '19 at 12:26
  • Well, yes I am sure, because nothing has changed in the code except for wrapping in a list. Yeah i also tried to run your code on my pc and it works with no errors! and, what interesting is!!! that i donno how and which magic happens that lets Rstudio make changes automatically in the code inside the helper file! it removes the **writeLines()** function, and removes the **con = "helper.r")** and removes the **source("helper.r")** and instead: `` myPopovers = list( bsPopover( id = "one", title = "ONE", ... etc.. ) `` – Jana Zuraik May 22 '19 at 12:34
  • In my example code above I'm writing `helper.R` to disk and source it afterwards to replicate your usecase. Accordingly `writeLines()` is the function to create the file and therefore it is not appearing as text in the file. – ismirsehregal May 22 '19 at 12:40
  • 1
    Aha! i got it, okay thank you very much @ismirsehregal that really helped – Jana Zuraik May 22 '19 at 12:59