Convert ggplot object graphically in brilliant application

I am trying to convert a ggplot object to design and show it in a brilliant application. But I ran into the error "not applicable method for" plotly_build "applied to an object of class" NULL ""

I managed to successfully return the ggplot object to a brilliant application,

output$plot1 <- renderplot({ gp <- ggplot(data = mtcars, aes(x = disp, y = cyl)) + geom_smooth(method = lm, formula = y~x) + geom_point() + theme_gdocs() }) 

but somehow he cannot transform it.

My code is as follows

 output$plot2 <- renderplotly({ gp <- ggplot(data = mtcars, aes(x = disp, y = cyl)) + geom_smooth(method = lm, formula = y~x) + geom_point() + theme_gdocs() ggplotly() }) 
+12
r shiny ggplot2 plotly
source share
2 answers

Try:

 library(shiny) library(ggplot2) library(ggthemes) library(plotly) ui <- fluidPage( titlePanel("Plotly"), sidebarLayout( sidebarPanel(), mainPanel( plotlyOutput("plot2")))) server <- function(input, output) { output$plot2 <- renderPlotly({ print( ggplotly( ggplot(data = mtcars, aes(x = disp, y = cyl)) + geom_smooth(method = lm, formula = y~x) + geom_point() + theme_gdocs())) }) } shinyApp(ui, server) 
+14
source share

If this is rendering in the RStudio panel instead of the application, make sure that you use plotlyOutput in the user interface section and also renderPlotly in the server section.

+5
source share

All Articles