Hi,
Yes plot() and ggplot() behave differently. If you do this: myPlot = ggplot(data, ...)
it will save a ggplot object to that variable without actually rendering it. If you then run myPlot
or if you just run ggplot(data, ...)
without assigning it, it will actually render the output to the graphics device. The plot function however always renders to the graphics device, and can't be stored into a variable, even if you try.
The renderPlot()
expects a rendered output, so this will produce results
output$myPlot = renderPlot({ggplot(data, ...)})
#OR
output$myPlot = renderPlot({plot(data)})
This one will not
output$myPlot = renderPlot({myPlot = ggplot(data, ...)})
Unless like this
myPlot = ggplot(data, ...)
output$myPlot = renderPlot({myPlot })
OR
output$myPlot = renderPlot({
myPlot = ggplot(data, ...)
myPlot
})
Hope this helps,
PJ