2015-10-26 71 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