在 shiny 中使用 navbarpage 时显示的样式标签

Style tag showing when using navbarpage in shiny

我想更改 DT 中行在我的应用程序中被选中时的颜色,而不是默认的蓝色。我使用了 并且它有效,但由于某种原因它在应用程序中显示了样式标签的文本。

我已经尝试更改为 fluidPage() 而不是 navbarPage() 并解决了这个问题 - 但我想将 navbarPage 用于我的导航选项卡!

我想我正在做一些愚蠢的事情 - 有什么想法吗?

示例代码:

library(shiny)
library(DT)
library(data.table)

example_data <- data.table(words = c("on", "scone", "wrong", "stone"), 
                           description = c("The word on", "Scone is not on", "Not on either", "Not here at all"))

ui = shinyUI(navbarPage(tags$style(HTML('table.dataTable tr.selected td, table.dataTable td.selected {background-color: cornsilk !important;}')),
                        title = "Random example",

    fluidRow(
      dataTableOutput("word_searched")
    )
  )
)


server = shinyServer(function(input, output, session) {

  output$word_searched <- renderDataTable({
    datatable(example_data)
  })

  })

shinyApp(ui = ui, server = server)

只需将 style$tag 部分放在 fluidRow 中即可。您不需要 HTML 样式标签中的函数:

library(shiny)
library(DT)
library(data.table)

example_data <- data.table(words = c("on", "scone", "wrong", "stone"), 
                           description = c("The word on", "Scone is not on", "Not on either", "Not here at all"))

ui = shinyUI(navbarPage(
  title = "Random example",
      fluidRow(
        tags$style('table.dataTable tr.selected td, table.dataTable td.selected {background-color: cornsilk !important;}'),
        dataTableOutput("word_searched")
      )
)
)


server = shinyServer(function(input, output, session) {

  output$word_searched <- renderDataTable({
    datatable(example_data)
  })

})

shinyApp(ui = ui, server = server)

输出: