Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does htmlwidgets on parent and child (nested) tables have to be the same? #125

Closed
choux130 opened this issue Feb 10, 2021 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@choux130
Copy link

First, I want to say thank you to all the contributors in this project. I love this package so much and look forward for more cool features to come! :)

Here is the question I have. I found that if htmlwidgets are not the same in parent and child table, the widgets in the child table will not show up. It is just blank. Is there any way to allow different htmlwidgets in nested table?

This is the example that I used sparkline in parent table and plotly in child table.

rm(list = ls())
gc()

pkg = c("reactable", "plotly", "sparkline")

lapply(pkg, FUN = function(X) {
  do.call("packageVersion", list(X)) 
})
# [[1]]
# [1] ‘0.2.3’
# 
# [[2]]
# [1] ‘4.9.3’
# 
# [[3]]
# [1] ‘2.0’

lapply(pkg, FUN = function(X) {
  do.call("require", list(X)) 
})

df_parent = data.frame(group = c(1,2,3), line = c(3,2,1)) 
df_child = data.frame(group2 = c(3,4,5), line2 = c(5,4,3))


reactable(df_parent, 
          columns = list(
            group = colDef(details = function(index) {
              htmltools::div(style = "padding-left: 160px",
                 reactable(
                   df_child,
                   columns = list(
                     line2 = colDef(
                       cell = function(value, index) {
                         # browser()
                         
                         # # sparkline
                         # sparkline(c(rnorm(10, 1, 3)))
                         
                         # plotly
                         data = data.frame(x = 1:10, y = rnorm(10))
                         fig <- plot_ly(data, x = ~x, y = ~y,
                                        height = 100,
                                        type = 'scatter',
                                        mode = 'lines')
                         as_widget(fig %>%
                                     config(displayModeBar  = FALSE))
                         
                         
                         
                       }
                     )
                   )
                 )
              )
              
            }), 
            line = colDef(cell = function(value, index) {
              # browser()
              # sparkline
              sparkline(c(rnorm(10, 1, 3)))
              
              # # plotly
              # data = data.frame(x = 1:10, y = rnorm(10))
              # fig <- plot_ly(data, x = ~x, y = ~y,
              #                height = 100,
              #                type = 'scatter',
              #                mode = 'lines')
              # as_widget(fig %>%
              #   config(displayModeBar  = FALSE))
            }))
)

Screen Shot 2021-02-10 at 12 22 03 PM

If we use all sparkline or all plotly, the plot will be shown up successfully.
Screen Shot 2021-02-10 at 12 35 48 PM
Screen Shot 2021-02-10 at 12 36 15 PM

@glin glin added the bug Something isn't working label Feb 13, 2021
@glin
Copy link
Owner

glin commented Feb 13, 2021

This should've worked, but there was a bug in the package that caused HTML dependencies of nested tables to be ignored. This should now be fixed in the development version if you want to try it out (768ed43).

If you can't use the development version, a workaround would be something similar to the second example - to render the widget somewhere else on the page so that its dependencies are present.

Thanks for the report!

@glin glin closed this as completed Feb 13, 2021
@choux130
Copy link
Author

Yes. I have tested out the development version and it works perfectly. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants