Sizing of plotD3 in Shiny
Closed this issue · 2 comments
Hello,
I'm attempting to use an iBreakdown plot in a Shiny app and I'm finding I'm unable to increase the size of the plot. According to r2d3 documentation, the plot should fill the area so I'm wondering if there's a bug on the 'iBreakDown' side rather than the 'r2d3' side.
Below, I've tried setting the container height of both the d3Output as well as the column within the fluidRow. I also tried setting scale_height=TRUE.
library(shiny)
library(r2d3)
library(DALEX)
library(iBreakDown)
ui <- fluidPage(
fluidRow(
column(12, style = "height:800px;",
d3Output("d3", height = "800px")
)
)
)
server <- function(input, output) {
output$d3 <- renderD3({
titanic <- na.omit(titanic)
set.seed(1313)
titanic_small <- titanic[sample(1:nrow(titanic), 500), c(1,2,6,9)]
model_titanic_glm <- glm(survived == "yes" ~ gender + age + fare,
data = titanic_small, family = "binomial")
explain_titanic_glm <- explain(model_titanic_glm,
data = titanic_small[,-9],
y = titanic_small$survived == "yes",
label = "glm")
bd_glm <- local_attributions(explain_titanic_glm, titanic_small[1, ])
plotD3(bd_glm) # also tried adding 'scale_height=TRUE'
})
}
shinyApp(ui = ui, server = server)
As for my info:
R version 3.5.3 (2019-03-11)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 16299)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] iBreakDown_0.9.9 DALEX_0.4.7 r2d3_0.2.3 shiny_1.3.2
loaded via a namespace (and not attached):
[1] Rcpp_1.0.1 compiler_3.5.3 pillar_1.3.1 later_0.8.0
[5] plyr_1.8.4 tools_3.5.3 digest_0.6.19 jsonlite_1.6
[9] tibble_2.1.1 gtable_0.2.0 pkgconfig_2.0.2 rlang_0.3.4
[13] rstudioapi_0.10 yaml_2.2.0 xfun_0.5 dplyr_0.8.0.1
[17] knitr_1.22 htmlwidgets_1.3 grid_3.5.3 tidyselect_0.2.5
[21] glue_1.3.1 R6_2.4.0 ggplot2_3.1.0 purrr_0.3.2
[25] magrittr_1.5 scales_1.0.0 promises_1.0.1 htmltools_0.3.6
[29] assertthat_0.2.1 mime_0.6 xtable_1.8-3 colorspace_1.4-1
[33] httpuv_1.5.0 lazyeval_0.2.2 munsell_0.5.0 crayon_1.3.4
Hi,
indeed the plot has a fixed height, it depends on number of variables and bar_width
parameter.
bar_width = 30
(in plotD3 function) will make your plot largerscale_height = TRUE
will make top and bottom margins the same sizeheight = "800px"
will change the size of svg (height = plot height + top margin + bottom margin)
Ah, my mistake. Sorry about that. I misunderstood the documentation. I thought bar_width
meant the width of each individual bar within the chart rather than the chart width.
Thank you!