Make bold text in HTML output R shiny

2020-03-01 07:30发布

Reproducible example:

require(shiny)
runApp(list(ui = pageWithSidebar(
headerPanel("Example"),
  sidebarPanel(
    sliderInput("index", 
                label = "Select a number",
                min = 1,
                max = 4,
                step = 1,
                value = 2)),
  mainPanel(
  htmlOutput("text")
  )),
server = function(input, output) {
  output$text <- renderUI({
    HTML(paste(c("banana","raccoon","duck","grapefruit")))
  })
}
))

I would like to have the word corresponding to index ("raccoon" in the default) displayed in bold and the other words in normal font.

If I do:

HTML(
<b>paste(c("banana","raccoon","duck","grapefruit")[input$index])<\b>,
paste(c("banana","raccoon","duck","grapefruit")[setdiff(1:4,input$index)])
)

I receive an error (< is not recognized)...

4条回答
smile是对你的礼貌
2楼-- · 2020-03-01 07:50

If you're not set on using the HTML function, I believe you should be able to use strong(paste(character_vector[index])) instead.

查看更多
男人必须洒脱
3楼-- · 2020-03-01 07:55

Just use renderPrint instead of renderText

renderPrint({
HTML(paste0("El valor 1 es:", input$val1,"\n","el valor 2 es:",input$val2))
})
查看更多
做个烂人
4楼-- · 2020-03-01 08:03

One more try, is this helpful?

require(shiny)

fruits <- c("banana","raccoon","duck","grapefruit")

runApp(list(ui = pageWithSidebar(
  headerPanel("Example"),
  sidebarPanel(
    sliderInput("index", 
                label = "Select a number",
                min = 1,
                max = 4,
                step = 1,
                value = 2)),
  mainPanel(
    htmlOutput("text")
  )),
  server = function(input, output) {
    output$text <- renderUI({
      fruits[input$index] <- paste("<b>",fruits[input$index],"</b>")
      HTML(paste(fruits))
    })
  }
))
查看更多
霸刀☆藐视天下
5楼-- · 2020-03-01 08:15

This might help you:

shinyApp(
  ui <- basicPage(
    uiOutput(outputId = "text")

  ),
  server <- function(input,output){

    output$text <- renderText({
      HTML(paste0("<b>","bold","</b>", " not bold"))
    })

  })

Is that what you were looking for?

查看更多
登录 后发表回答