Make bold text in HTML output R shiny
40,410
Solution 1
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))
})
}
))
Solution 2
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?
Solution 3
If you're not set on using the HTML
function, I believe you should be able to use strong(paste(character_vector[index]))
instead.
Author by
Antoine
[Homepage]. Research Scientist in AI. Previously postdoc in AI @ Polytechnique (Palaiseau, France), PhD & Master @ CU Boulder. R, R Shiny, and Python user. A web application that I developed.
Updated on July 14, 2022Comments
-
Antoine almost 2 years
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)...