Some plots not showing in plot pane (while others do show)

I'm having trouble getting some plotting functions to work, while others work fine. Here's an example. The first plot (with plot() function) works fine. The second plot with DiagrammeR mermaid() function doesn't work. The plot pane goes blank, and for some reason the 'Viewer' pane becomes the active pane, rather than the 'Plots' pane, but the Viewer pane remains blank too (i.e. I am not able to see any output). There is no error nor warning shown in the console.

# example I'm trying to work through, from

df <- data.frame(task = c("task1", "task2", "task3"),
                 status = c("done", "active", "crit"),
                 pos = c("first_1", "first_2", "first_3"),
                 start = c("2014-01-06", "2014-01-09", "after first_2"),
                 end = c("2014-01-08", "3d", "5d"))

plot(df$task, df$end) # random plot which DOES show in the plots pane

# Using dplyr and tidyr (or any of your favorite data wrangling resources):
library(tidyr); library(dplyr)

    # mermaid "header", each component separated with "\n" (line break)
    "gantt", "\n", 
    "dateFormat  YYYY-MM-DD", "\n", 
    "title A Very Nice Gantt Diagram", "\n",
    # unite the first two columns (task & status) and separate them with ":"
    # then, unite the other columns and separate them with ","
    # this will create the required mermaid "body"
    paste(df %>%
            unite(i, task, status, sep = ":") %>%
            unite(j, i, pos, start, end, sep = ",") %>%
          collapse = "\n"
    ), "\n"

can anyone help to please assist me to understand what's going on and how to plot this thing?

Is it just meant to open up in the viewer pane? You can get it to plot in a RMarkdown document if that helps:

Thanks Williaml,

It doesn't show in the viewer window either... and I'm not using markdown (just a regular script in RStudio).

I didn't have any issues with it. Did the packages install correctly? Otherwise, I have no idea.

Thanks again. The packages installed correctly with no issues.

I think the fact that standard plots go to plots and some plotting type packages follow that convention and others go to viewer is just something to accept about RStudio IDE... I think viewer is more general purpose, and for example a lot of R advanced graphics is repackaged JavaScript libraries where the natural route is to show on the viewer. (Allows interactivity like hover interactive content)
Typically both plots and viewer are used interactively, and for documented work you'd be outputting images of plots to graphic files or embedding into markdown documents, or serving through shiny apps, so I'm not understanding how it's really an issue to a workflow...

Thanks nirgrahamuk,

I guess I didn't make myself clear enough in the first instance. The plot does not show up anywhere - the viewer pane remains blank too. I have edited the question to make this clearer.

Thanks for clarifying, it must be very frustrating for you to not get the output you want to see at all.
Does this behaviour persist after restarting R by the Ctrl+Shft+F10 method?

Thanks again Nirgrahamuk,

Control+shift+F10 didn't work for me, but i looked it up and found that this is a shortcut for Session > Restart R so did that instead. It still doesn't work (switches to 'Viewer' tab, which is blank; plot pane goes blank too).


At this point I would uninstall RStudio and reinstall it.

Wow! That worked. Thank you Nir. I had no idea that it could be a fault of RStudio; it's worked so well for me till now.

1 Like

Glad we found a solution, shame it had to be a rather crude one ! :slight_smile:

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