kcuilla / reactablefmtr

Streamlined Table Styling and Formatting for Reactable
https://kcuilla.github.io/reactablefmtr/
Other
206 stars 27 forks source link

The add_title() function does not work in shiny. #40

Open akins11 opened 2 years ago

akins11 commented 2 years ago

Thank you for this wonderful package. When using the add_title() function in shiny, no title is displayed. see:


library(shiny)
library(reactable)
library(reactablefmtr)

ui <- fluidPage(
  reactableOutput(outputId = "table")
)

server <- function(input, output, session) {
  output$table <- renderReactable({
    reactable(data = mtcars) |>
      add_title(title = "Motor Trend Car Table")
  })
}
shinyApp(ui, server)

table_with_no_title

Using the function without shiny:


reactable(data = mtcars) |>
  add_title(title = "Motor Trend Car Table")

table_with_title

R.version platform x86_64-w64-mingw32
arch x86_64
os mingw32
crt ucrt
system x86_64, mingw32
status
major 4
minor 2.1
year 2022
month 06
day 23
svn rev 82513
language R
version.string R version 4.2.1 (2022-06-23 ucrt) nickname Funny-Looking Kid

> packageVersion("reactable")
[1] ‘0.3.0’
> packageVersion("reactablefmtr")
[1] ‘2.0.0’
> packageVersion("shiny")
[1] ‘1.7.2’
kcuilla commented 1 year ago

Hi, thanks for using reactablefmtr. Unfortunately, the title, subtitle, and source aren't compatible with Shiny because their properties get masked by the Shiny HTML. I'll be sure to add this to the documentation so that users know ahead of time.

A work-around I'd recommend is adding the title above the table within the ui section of the Shiny app like below:

library(shiny)
library(reactable)
library(reactablefmtr)

ui <- fluidPage(
  h2("Motor Trend Car Table"), # add title above table
  reactableOutput(outputId = "table")
)

server <- function(input, output, session) {

  output$table <- renderReactable({
    reactable(data = mtcars)
  })
}
shinyApp(ui, server)

image