dm_draw() in 'dm' package produces error: layout was not done

Hi there,

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!

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()

All this returns a white window with Error: Layout was not done.

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()
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.