0

The plot function of some packages like timetk, plot_ly does not produce the plot(output) written inside renderPlot function. Although the same piece of code returns the output(plot) when I run it in console. Whereas function like plot(), ggplot() does the work too. Why is that so?

This piece of code with timetk library provide the output in rstudio console:

dataset %>%
      plot_time_series(.date_var = Year, .value = column1,
                       .interactive = TRUE, .y_lab = "Amt", .x_lab = "Year",
      )

But if this same piece is written inside renderPlot function, it does not provide the output on RShiny app, just shows a blank white screen.

UI: UI code is all good. I also have written an plotOutput("p1") too.

Server:

output$p1 <- renderPlot({ 
dataset %>%
      plot_time_series(.date_var = Year, .value = column1,
                       .interactive = TRUE, .y_lab = "Amt", .x_lab = "Year",
      )
})
benson23
  • 16,369
  • 9
  • 19
  • 38
RShiny_Noob
  • 47
  • 1
  • 6
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Apr 22 '21 at 19:22
  • 2
    Try with `plotly::renderPlotly` and `plotly::plotlyOutput`. – stefan Apr 22 '21 at 21:00
  • @stefan Hey, this was the problem, thanks. – RShiny_Noob May 27 '21 at 06:46
  • @stefan Can you post this as an answer so that I can accept it and close this post. :) – RShiny_Noob May 27 '21 at 06:46

1 Answers1

0

The issue is (was) that renderPlot and plotOutput are meant for base plots or ggplots. As you want to make an interactive plotly chart you have to make use of plotly::renderPlotly and plotly::plotlyOutput.

stefan
  • 90,330
  • 6
  • 25
  • 51