0

当我在 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)

但是,当我使用闪亮执行相同的代码时

reactableOutput("table_1")  

output$table_1 <- renderReactable({

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)

})

它给出了错误:

renderWidget(instance) 中的警告:忽略前置内容;prependContent 不能在 Shiny 渲染调用中使用

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

4

2 回答 2

1

您可以在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)

请注意,您的代码给了我同样的错误,但我确实在 RStudio 的查看器窗格中得到了正确的输出。

于 2020-10-27T21:12:12.710 回答
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")

再次感谢。

于 2020-10-28T04:44:36.237 回答