daattali / ggExtra

📊 Add marginal histograms to ggplot2, and more ggplot2 enhancements
http://daattali.com/shiny/ggExtra-ggMarginal-demo/
Other
383 stars 48 forks source link

Does ggMarginalGadget(plot) work from the Console Panel (Rstudio)? #158

Closed sfd99 closed 3 years ago

sfd99 commented 3 years ago

Hi Dean,

ggExtra = great, useful pkg!.

ggMarginalGadget(plot) or the equivalent Addin. works great from Rstudio's [Source Panel].

But,... from Rstudio's [Console Panel]

Using the ggextra Vignette example, for: ggMarginalGadget(plot)

if (interactive()) { plot <- ggplot2::ggplot(mtcars, ggplot2::aes(wt, mpg)) + ggplot2::geom_point() plot2 <- ggMarginalGadget(plot) }

pops up the interface, but w/ this error message: (in red letters):

_Error with the advanced options: no applicable method for 'ggplotbuild' applied to an object of class "NULL"

Does the ggMarginalGadget() Fx work in the Rstudio [Console Panel] or only from the [Source Panel] ?.

help! sfd99 San Francisco latest Rstudio, R, Ubuntu Linux 20.04.

daattali commented 3 years ago

Thanks for the report!

I've been able to pinpoint the issue to a difference between retrieving an object that has the same name as an internal function (such as plot) from within a package's function vs outside of a package function. It looks like at some point, perhaps because of changes to R, it changed.

To show you what I mean:

This is why the example code using the variable name "plot" is breaking. I don't know when this started happening. I'll change the example to a different variable name.

daattali commented 3 years ago

fixed in https://github.com/daattali/ggExtra/commit/e23ccb9810190b42e6069bd7899978602194581e

sfd99 commented 3 years ago

Thanks Dean for the fix. That was quick!. :-)

ggMarginal(p) now works fine from the Rstudio [Console Panel].

But, the Addin alternative, with: p <- ggplot(mtcars, aes(wt, mpg)) + geom_point()

ie: highlight p in the [Console Panel] then click on: "ggplot Marginal Plots" in Addins, still gives an error message:

> ggExtra:::ggMarginalGadgetAddin () Error in ggExtra:::ggMarginalGadgetAddin() : Please highlight a ggplot2 plot before selecting this addin.

Yet, the letter p in the [Console Panel] (a ggplot), has been hilited before clicking on the Addin. as prescribed.

Maybe I'm missing something basic?... sfd99 San Francisco latest Rstudio, R, Ubuntu Linux 20.04. ggextra Version 0.9.0.1 - installed f/GIThub.

daattali commented 3 years ago

It may have seemed quick to you but it was a very long frustrating hour of debugging for me :)

p causes the same issue. p is a function in shiny (well, actually, in htmltools), for creating paragraph in HTML. Basically you can't use a variable that is already a function.

I'll reopen this because this problem should be handled better rather than my bandaid solution of "don't do this". It's strange that this never used to be an issue

sfd99 commented 3 years ago

Thanks, Dean!.

Your hard work and useful R PKG contributions are highly appreciated.

You are a true PRO...