2
我想弄清楚如何在ShockPlot的renderPlot函數中創建「height」變量從renderPlot()中接收變量。這是server.R我的代碼:如何使renderPlot()中的「height」參數在Shiny R包中動態化
shinyServer(function(input, output) {
output$contents <- renderPlot({
file<-input$file #a CSV file is uploaded
file<-with(file,
aggregate(file[, input$metricIn],
by=list(period=day,
dimension1=file[, input$dimension1In],
dimension2=file[, input$dimension2In]),
FUN = input$funIn, na.rm=TRUE))
#input$dimension1In is column name from file
#input$dimension2In is column name from file
#count of facets in the plot to calculate height in renderPlot height argument
facetCount<<-as.numeric(length(unique(file[, input$dimension1In]))) * 100
plot<-reactive({
g<-ggplot(data = file, aes_string(x=input$dimension2In,
y=input$metricIn, fill=period))
plot<-g + geom_bar(stat="identity", position=position_dodge()) +
facet_wrap(as.formula(paste("~", input$dimension1In)),
scales = "free", ncol=1)
}) #end of reactive
print(plot())
}, width=1000,
height = facetCount)
}) #end of shinyServer
所以我的問題是高度的說法是renderPlot沒有看到facetCount變量,甚至當我使用< < - 分配裏面renderPlot。
我想讓高度動態,因爲如果有很多方面要繪製,我希望繪圖高度相應地進行調整。