2015-10-26 72 views
1

我有一個Shiny應用程序和一個R腳本,我想嵌入到我的Shiny應用程序中。該腳本輸出一個ggplot,我不知道如何讓它出現在我的Shiny App中。我已經排除了一些無關的代碼。該腳本已成功調用,並且變量存儲在我的工作區中,但不顯示任何內容。如何使用source()以閃亮的方式顯示ggplot輸出?

我已經列入我server.R文件中的以下內容:

##server.R## 
source("heatmap.R", local=TRUE) 

output$heatmap <- renderPlot ({ 
heatmapOutput 
}) 

##ui.R## 
shinyUI(fluidPage(
column(10, plotOutput("heatmap")) 
    ), 
+1

你嘗試保存ggplot給一個變量,並把它傳遞給渲染圖功能? –

+1

如果我將圖保存到'heatmap.R'中的'heatmapOutput',並像修改後的代碼中那樣調用它,那會起作用嗎? – Gary

+0

我會在'heatmap.R「裏放置'output $ heatmap < - renderPlot({你所有的代碼都是製作heatmapOutput})'。然後,就像你在服務器上的源一樣,並且不需要重寫'output $ heatmap < - ...' – jenesaisquoi

回答

1

output必須是內shinyServer

shinyServer(function(input, output) { 
    output$heatmap <- renderPlot ({ heatmapOutput }) 
} 
+0

我在'shinyServer'裏面有它,但是沒有任何東西顯示出來。我可以直接將代碼複製並粘貼到我的Shiny應用程序中嗎? – Gary

+0

我通過將'ggplot'代碼顯式粘貼到'output $ heatmap'中解決了這個問題,並且它可以工作,因爲所有變量都已成功加載。 – Gary