boxuancui / DataExplorer

Automate Data Exploration and Treatment
http://boxuancui.github.io/DataExplorer/
Other
512 stars 88 forks source link

Suggestion: don't print ggplot object in DataExplorer:::plotDataExplorer.single() #133

Closed RoelVerbelen closed 4 years ago

RoelVerbelen commented 4 years ago

Thanks for your package! I'm using your plot_correlation() function in an R Markdown and am converting it to a plotly graphic via ggplotly():

library(DataExplorer)
library(plotly)
plot_correlation(iris) %>% ggplotly()

However, this command leads to first plotting it as a ggplot object and then as a plotly object.

This could be solved/prevented by deleting the print(plot_obj) line in DataExplorer:::plotDataExplorer.single(). The ggplot object is returned invisibly in the last line anyway. Would that be something you would consider doing or would it break your functionality elsewhere?

boxuancui commented 4 years ago

Yes, plots don't show up during non-interactive mode (See this SO answer). There is no silver bullet here, so I chose to have it printed by default.

For your R Markdown use case, I suggest separating the code block into an include=FALSE section:

```{r create, include=FALSE}
library(DataExplorer)
library(plotly)
out <- plot_correlation(iris)

Then call the output from another block:

````R
```{r plot}
ggplotly(out)
RoelVerbelen commented 4 years ago

Thanks for your response. I understand the trade-off. In R markdown, the workaround is easy enough.