在HTML输出R中创建粗体文本

Ant*_*ine 14 html formatting r shiny

可重复的例子:

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")))
  })
}
))
Run Code Online (Sandbox Code Playgroud)

我希望对应于索引(默认情况下为"raccoon")的单词以粗体显示,而其他单词以普通字体显示.

如果我做:

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

我收到错误(<无法识别)...

Seb*_*ian 22

再试一次,这有用吗?

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))
    })
  }
))
Run Code Online (Sandbox Code Playgroud)

  • 非常感谢你!在"水果"中存放浣熊和鸭子的+1 (4认同)

Seb*_*ian 8

这可能对您有所帮助:

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

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

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

  })
Run Code Online (Sandbox Code Playgroud)

那是你在找什么?


Jas*_*lns 5

如果您不打算使用该HTML功能,我相信您应该可以使用strong(paste(character_vector[index]))