shinydashboardPlus icon indicating copy to clipboard operation
shinydashboardPlus copied to clipboard

textOutput elements within flipBox -- does not display for tags$h1

Open McCartneyAC opened this issue 3 years ago • 2 comments

I'm not sure if this is something broken within shinydashboardPlus, ShinyDashboard, Shiny, or just me, but I've been struggling with it for a while.

In the following two reprexes, one version of h1(textOutput("")) loads if-and-only-if it is not called a second time on the back. Without the second h1(textoutput()) call, it works on the front of the flipbox.

this version works

shinyApp(
  ui = dashboardPage(
    dashboardHeader(),
    dashboardSidebar(),
    dashboardBody(
      fluidRow(
        column(
          width = 6,
          flipBox(
            id = "myflipbox2",
            width = 12,
            front = div(
              h1(textOutput("textsample")),
              img(
                src = "https://image.flaticon.com/icons/svg/149/149076.svg",
                height = "300px",
                width = "100%"
              )
            ),
            back = div(
              height = "300px",
              width = "100%",
             # h1(textOutput("textsample")), # notice this is commented out
              p("More information....")
            )
          )
        )
      )
    )
  ),
  
  server = function(input, output, session) {
    output$textsample <- renderText(
      "this is header text"
    )
  }
)

This version does not display any text

shinyApp(
  ui = dashboardPage(
    dashboardHeader(),
    dashboardSidebar(),
    dashboardBody(
      fluidRow(
        column(
          width = 6,
          flipBox(
            id = "myflipbox2",
            width = 12,
            front = div(
              h1(textOutput("textsample")),
              img(
                src = "https://image.flaticon.com/icons/svg/149/149076.svg",
                height = "300px",
                width = "100%"
              )
            ),
            back = div(
              height = "300px",
              width = "100%",
              h1(textOutput("textsample")), # here it is not commented out, but the previous h1 also does not display. 
              p("More information....")
            )
          )
        )
      )
    )
  ),
  server = function(input, output, session) {
    output$textsample <- renderText(
      "this is header text"
    )
  }
)

Please tell me I'm making a simple mistake somewhere.

McCartneyAC avatar Apr 27 '21 17:04 McCartneyAC

I will add that in the use case I'm trying to do, it doesn't work even if I include it just once, where I am calling for a character string derived from the server as:

    article1_headline<-renderText(
      newstable %>% 
        dplyr::filter(row_number()==1) %>% 
        dplyr::select(headline) %>% 
        as.character()
    )

h1(textOutput("article1_headline")) has never worked.

McCartneyAC avatar Apr 27 '21 17:04 McCartneyAC

The problem is that you give the same id ("textsample") to two outputs which makes none of them appear. You need to give two different ids.

Regarding your second comment, you should use output$article1_headline instead of article1_headline

etiennebacher avatar Apr 30 '22 19:04 etiennebacher