Just installed 'dm' package and trying to play around with relational data in r. However, dm_draw() doesn't seem to work. I tried it with my own data frames but also from an example data frames from Relational Data Models • dm and it still doesn't generate any image, it's just a white page with an error message: Error: Layout was not done. Any ideas how to fix this? Thank you!
Hey there, I ran into the same issue and couldn't identify the cause in a timely manner so I decided on an interim solution of converting the dm_draw output to svg and printing in the viewer. I called this function dm_draw_svg. Please see the following (note: you'll need to install DiagrammeRsvg)
library(dm)
dm_draw_svg = function(dm,...) {
if (!requireNamespace("DiagrammeRsvg", quietly = TRUE)) {
stop(
"Package \"DiagrammeRsvg\" must be installed to use this function.",
call. = FALSE
)
}
dm::dm_draw(dm = dm, ...) %>%
DiagrammeRsvg::export_svg() %>%
htmltools::HTML() %>%
htmltools::html_print()
}
df1 <- data.frame(x = letters[range(1:10)], y = sample(seq(1, 10)))
df2 <- data.frame(x = letters[range(1:10)], y = sample(seq(1, 10)))
dm <- dm(df1, df2)
dm.pks <- dm %>%
dm_add_pk(df1, x) %>%
dm_add_pk(df2, x)
dm.all.keys <- dm.pks %>%
dm_add_fk(df1, x, df2)
dm.all.keys %>%
dm_draw_svg()