Change size, color of badge and text of dragulaInput

Deadly 提交于 2020-12-15 11:44:56

问题


I use package esquisseto create the input, I wonder how I change size of the badge, color text and badge color?

if (interactive()) {
  
  library("shiny")
  library("esquisse")
  
  
  ui <- fluidPage(
    tags$h2("Demo dragulaInput"),
    tags$br(),
    dragulaInput(
      inputId = "dad",
      sourceLabel = "Old",
      targetsLabels = c("New"),
      choices = levels(iris[,"Species"]),
      width = "250px",
      height = "100px",
      status = "danger"
    ),
    verbatimTextOutput(outputId = "result")
  )
  
  
  server <- function(input, output, session) {
    
    output$result <- renderPrint({
      new_level <- input$dad$target$New
      new_level_1 <- c(new_level,input$dad$source)
       })
    
  }
  
  shinyApp(ui = ui, server = server)
  
}


回答1:


You'll have to change the css properties of the badges. If you inspect the badge html, you'll see that they are each in a <span> tag with id=label-dragula label label-danger.

Since a span tag doesn't respond to height and width directives, you'll have to turn it into an inline-block element to change the size (thanks to this post). All of this is done in the tags$style() function - width and height are self-explanatory, background-color is the color of the badge and color is the color of the text.

library("shiny")
library("esquisse")


ui <- fluidPage(
  tags$h2("Demo dragulaInput"),
  tags$br(),
  tags$style("
    span.label-danger{
      display: inline-block;
      width: 75px;
      height: 75px;
      background-color: blue;
      color: red;
      font-size: 25px;
    }
    "),
  dragulaInput(
    inputId = "dad",
    sourceLabel = "Old",
    targetsLabels = c("New"),
    choices = levels(iris[,"Species"]),
    width = "250px",
    height = "200px",
    status = "danger"
  ),
  verbatimTextOutput(outputId = "result")
)


server <- function(input, output, session) {
  
  output$result <- renderPrint({
    new_level <- input$dad$target$New
    new_level_1 <- c(new_level,input$dad$source)
  })
  
}

shinyApp(ui = ui, server = server)



来源:https://stackoverflow.com/questions/63729957/change-size-color-of-badge-and-text-of-dragulainput

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!