rstudio / gt

Easily generate information-rich, publication-quality tables from R
https://gt.rstudio.com
Other
1.98k stars 200 forks source link

Nanoplots do not shade area beneath when on second tab #1601

Open joeycouse opened 6 months ago

joeycouse commented 6 months ago

Bug where nanoplots area are not shaded when on the second tab. Believe the issue is related to the fill = url(#area-pattern) argument not being found when the plot is a on a separate tab.

library(shiny)
library(bslib)
#> 
#> Attaching package: 'bslib'
#> The following object is masked from 'package:utils':
#> 
#>     page
library(gt)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

# Define the UI
ui <- fluidPage(
      navset_card_underline(
        nav_panel("table1",gt_output("table1")),
        nav_panel("table2",gt_output("table2"))
      )
)

# Define the server code
server <- function(input, output) {

  output$table1 <- render_gt(
    mtcars |> 
      head(10) |> 
      mutate(hp_1 = hp +1,
             hp_2 = hp + 3) |> 
      gt() |> 
      cols_nanoplot(columns = starts_with("hp"))
  )

  output$table2 <- render_gt(
    mtcars |> 
      head(10) |> 
      mutate(hp_1 = hp +1,
             hp_2 = hp + 3) |> 
      gt() |> 
      cols_nanoplot(columns = starts_with("hp"))
  )

}

# Return a Shiny app object
shinyApp(ui = ui, server = server)
Shiny applications not supported in static R Markdown documents

Created on 2024-03-07 with reprex v2.0.2

https://github.com/rstudio/gt/assets/54423399/91823931-4d75-46b2-8ad9-9ebc78b29156

rich-iannone commented 6 months ago

Thank you for reporting this issue! I could definitely add a fix for this quite soon. Note to self: it probably would be best to have a uniquely generated ID for each instance of the the fill pattern (then refer to that ID within the SVG content).