Shiny 如何为使用renderReactable创建的表指定标题

Shiny 如何为使用renderReactable创建的表指定标题,shiny,reactable,Shiny,Reactable,当我在R中执行以下代码时,它工作得很好 example<- reactable(data.frame(country=c("argentina","brazil"), value=c(1,2) )) withtitle <- htmlwidgets::prependContent(example, h

当我在R中执行以下代码时,它工作得很好

example<- reactable(data.frame(country=c("argentina","brazil"),
                               value=c(1,2)
))
withtitle <- htmlwidgets::prependContent(example, 
                                         h2(class = "title", "Top CRAN Packages of 2019"))
print(withtitle)

请指导我为上表提供标题以及标题的其他参数,如背景色、字体颜色等。

您可以在
ui
部分定义标题。也许你在找这个

library(reactable)

ui <- fluidPage(
  h2("Top CRAN Packages of 2019"),
  reactableOutput("table_1")
)
 
server <- function(input, output) {
  output$table_1 <- renderReactable({
    
    example<- reactable(data.frame(country=c("argentina","brazil"),value=c(1,2)))

  })
}

shinyApp(ui = ui, server = server)
库(可反应)

ui您可以在
ui
部分定义标题。也许你在找这个

library(reactable)

ui <- fluidPage(
  h2("Top CRAN Packages of 2019"),
  reactableOutput("table_1")
)
 
server <- function(input, output) {
  output$table_1 <- renderReactable({
    
    example<- reactable(data.frame(country=c("argentina","brazil"),value=c(1,2)))

  })
}

shinyApp(ui = ui, server = server)
库(可反应)

ui谢谢YBS。我从你的回答中得到了这个想法。在reactableOutput()之前,我在ui中使用了div()文本,可以获得颜色和背景可选的标题。使用的代码如下所示:

            div("Top CRAN Packages of 2019", style = "text-align: center; 
                  background-color: #3380FF; color:yellow; font-size:200%"),
            reactableOutput("table_1")

再次感谢。

谢谢YBS。我从你的回答中得到了这个想法。在reactableOutput()之前,我在ui中使用了div()文本,可以获得颜色和背景可选的标题。使用的代码如下所示:

            div("Top CRAN Packages of 2019", style = "text-align: center; 
                  background-color: #3380FF; color:yellow; font-size:200%"),
            reactableOutput("table_1")

再次感谢。

非常感谢。是的,我在查看器窗格中也得到了正确的输出,但在使用主代码运行时却没有得到正确的输出。然而,在ui中定义标题进展顺利。在ui中定义后,您能建议如何更改标题的颜色和背景色吗?非常感谢。是的,我在查看器窗格中也得到了正确的输出,但在使用主代码运行时却没有得到正确的输出。然而,在ui中定义标题进展顺利。您能建议在ui中定义后如何更改标题的颜色和背景色吗?