2016-06-06 2 views
7

ggplot 객체를 플롯으로 변환하고 반짝이는 응용 프로그램에 표시하려고합니다. 하지만 NULL "" ggplot 객체를 반짝이는 응용 프로그램으로 플롯 변환

내가 성공적으로 반짝 응용 프로그램에 ggplot 개체를 반환 할 수 있었다

,

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

하지만 어떻게 든 " 'plotly_build'에 대한 적용 방법은 클래스의 객체에 적용되지 않습니다"오류가 발생했습니다 음모가 그것을 변환 할 수 없습니다.

내 코드는이

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

사용 renderPlotly 대신 – MLavoie

답변

9

시도처럼 보인다 :

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) 
+0

감사하지만 여전히 작동하지 않습니다. – athlonshi

+0

죄송합니다. 또 한번 시도 해봐. –

+1

지금 작동 중입니다. 실제로 ggplotly 또는 print (ggplotly())는 정상적으로 작동합니다. ggplot에서 plly로 변경을 적용하려면 반짝이는 서버를 다시 시작해야한다는 것을 알았습니다. 이것이 정상인지 아닌지는 모르지만 웹 서버에서 Rstudio와 vs를 비교할 때 일관성없는 관찰이있었습니다. – athlonshi

관련 문제