Usha
Usha

Reputation: 17

How to change the background color of textboxes that are created dynamically in R shiny?

textInput(paste0("inp1-", wid),label = NULL,value = record$Current_week)

This is the code I used to create the text input boxes dynamically, the id for the text input box depends on the wid(which is a number).

I tried using following CSS format to change the background color, but it didn't work.

tags$head(tags$style(HTML('#',paste0("inp1-", wid),'{background-color:#f1c232;}')))

Please help me in solving this problem.

Upvotes: 1

Views: 1600

Answers (1)

Florian
Florian

Reputation: 25385

See here for an example where the input is not created dynamically. In your case, you could do as follows:

library(shiny)

wid=2

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


server <- function(input, output) {

  output$my_ui <- renderUI({
    tagList(
      textInput(paste0("inp1-", wid),label = NULL,value = 0),
      tags$style(paste0("#inp1-", wid,"{background-color:#ff0000;}"))
    )
  })
}

# Run the application 
shinyApp(ui = ui, server = server)

Hope this helps!

Upvotes: 1

Related Questions