John
John

Reputation: 43309

Style shiny variable with css tags

How do I style a variable in a shiny app with custom css?

I am working through the beginner's tutorial and I wish to place emphasis on a variable in this code:

library(shiny)

shinyServer(function(input, output){
    output$text1 <- renderText({
        paste("you have selected ",  input$var, " from the dropdown selector")
    })

    output$text2 <- renderText({
        paste("You have selected the range", input$range[1], 'to', input$range[2])
    })


})

I want to place emphasis on input$var and I have tried em(input$var) to no avail.

Anyone know the trick?

Upvotes: 1

Views: 606

Answers (1)

DeanAttali
DeanAttali

Reputation: 26383

Something like this would work (not tested code, but it's the right idea)

ui <- fluidPage(
    "you have selected",
    em(textOutput("text1")),
    "from the dropdown selector"
)

server <- function(input, output) {
  output$text1 <- renderText({ input$var })
}

Or, if you really want to do all the rendering on the server side, then you could use uiOutput+renderUI instead of text

ui <- fluidPage(
    uiOutput("text1")
)

server <- function(input, output) {
  output$text1 <- renderUI({
    tagList(
      "you have selected",
      em(input$var),
      "from the dropdown selector"
    )
  })
}

Upvotes: 2

Related Questions