【问题标题】:Formatting RHandsontable with ShinyThemes使用 ShinyThemes 格式化 RHandsontable
【发布时间】:2019-07-15 03:04:57
【问题描述】:

我正在尝试在 RHandsontable 中格式化下拉列表,但无济于事。

这是一些可重现的代码:

library(shiny)
library(dplyr)

DF <- data.frame(Value = 1:10)
choices <- 1:20


ui <- shinyUI(fluidPage(theme = shinytheme("darkly"),

        rHandsontableOutput("hot")
        ,h4("This is example text from the theme.")


  ))

server = (function(input, output) {

    values <- reactiveValues()

    ## Handsontable
    observe({
      if (!is.null(input$hot)) {
        values[["previous"]] <- isolate(values[["DF"]])
        DF = hot_to_r(input$hot)
      } else {
        if (is.null(values[["DF"]]))
          DF <- DF
        else
          DF <- values[["DF"]]
      }
      values[["DF"]] <- DF
    })

    output$hot <- renderRHandsontable({
      DF <- values[["DF"]]
      if (!is.null(DF)) {
        rhandsontable(DF) %>%
          hot_col(col = c("Value"), type = "dropdown", source = choices, strict = TRUE, allowInvalid = FALSE) %>%
          hot_cols(renderer = "
                   function(instance, td, row, col, prop, value, cellProperties) {
                   Handsontable.renderers.DropdownRenderer.apply(this, arguments);
                   td.style.color = 'gray';
                   }
                   ")
      }
    })


    })


shinyApp(ui = ui, server = server)

我遇到的问题是 ShinyThemes 包覆盖了默认字体颜色,使下拉菜单的白色背景上的字体颜色为白色。我发现了一些代码将 in 表中值的字体颜色更改为灰色(参见代码)。但是,此字体颜色不适用于下拉菜单。

如何更改下拉菜单的字体颜色和/或背景?

【问题讨论】:

    标签: r shiny rhandsontable shinythemes


    【解决方案1】:

    使用这个 CSS:

    css <- "
    .handsontable.listbox td {
      background: black;
    }
    .handsontable.listbox td.htDimmed {
      color: red;
    }
    .handsontable.listbox tr:hover td {
      background: yellow; 
    }
    .handsontable.listbox tr td.current {
      background: green; 
    }"
    ui <- shinyUI(fluidPage(theme = shinytheme("darkly"),
                            tags$head(tags$style(HTML(css))),
                            ......
    

    【讨论】:

    • 耶耶耶耶。谢谢你。我应该在花两个小时之前把这篇文章放在一起......或者这个练习对我有好处:)
    • @Caleb 很高兴为您提供帮助。请考虑accepting the answer。否则,您的问题将被 SO 视为未回答。
    • 是的,正在等待能够实施以确认它有效。干杯,它奏效了。
    猜你喜欢
    • 2019-06-16
    • 2019-07-15
    • 2020-12-02
    • 2022-10-01
    • 2018-07-08
    • 2016-08-10
    • 2019-02-15
    • 2018-10-03
    • 2020-12-03
    相关资源
    最近更新 更多