简体   繁体   中英

Escape HTML in dynamic box title of shinydashboard

I want to dynamically change the title of a box in a shinydashboard based on selectInput() selection but I cannot escape the HTML .

library(shiny)
library(shinydashboard)
library(htmltools)
ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    selectInput("plottype", "Select plot type", c("AP:TOTAL","FF:TOTAL","OVERALL")),
    box(title=paste(htmlEscape(textOutput('box1title')),"charts"),
        width = 6,
        solidHeader = TRUE,
        status = "primary",
        p('Use the checkbox to change the title of this box.')
    )
  )
)

server <- function(input, output) {
  output$box1title <- renderText({
    if(input$plottype=="AP:TOTAL"){
      "AP:TOTAL"
    }
    else if(input$plottype=="FF:TOTAL"){
      "FF:TOTAL"
    }
    else{
      "OVERALL"
    }
    
  })
}

shinyApp(ui,server)

Don't to the paste() in the UI, do the paste in the server function

Just use the plain test output for the box title

box(title = textOutput('box1title'), ...)

And then in the server do

output$box1title <- renderText({
    part <- if(input$plottype=="AP:TOTAL"){
      "AP:TOTAL"
    }
    else if(input$plottype=="FF:TOTAL"){
      "FF:TOTAL"
    }
    else{
      "OVERALL"
    }
    paste(part, "charts")
  })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM