Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Go back to the assign() based approach
  • Loading branch information
cpsievert committed Jun 25, 2020
commit 9114b8ad82172a368bf5ec3f83b5c7b52b4121b1
21 changes: 12 additions & 9 deletions R/ggplotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,13 @@ gg2list <- function(p, width = NULL, height = NULL,
suppressMessages(dplyr::left_join(x, y))
}, data, nestedKeys, layers)

# return all the objects in this environmet
mget(ls(environment()), inherits = FALSE)
structure(
list(
data = data, layout = layout, plot = plot,
env = environment()
),
class = "ggplot_built"
)
}

# Allow thematic to add new defaults to the plot object based on it's theme
Expand All @@ -431,15 +436,13 @@ gg2list <- function(p, width = NULL, height = NULL,
ggplotly_build(p)
}

# ggplotly_build() returns list of objects...make them known to gg2list() env

env <- environment()
for (var in names(built)) {
assign(var, built[[var]], envir = env)
# Assign all the objects available to ggplotly_build() to this functions environment
built_env <- built$env
envir <- environment()
for (var in ls(built_env)) {
assign(var, built_env[[var]], envir = envir)
}
Comment thread
cpsievert marked this conversation as resolved.



# initiate plotly.js layout with some plot-wide theming stuff
theme <- ggfun("plot_theme")(plot)
elements <- names(which(sapply(theme, inherits, "element")))
Expand Down