2017-11-13 1 views
0

Haben Sie einen Fehler hier? die ggsave funktioniert, aber png(file=file) Teil nicht - es speichert leeres weißes Bild.Speichern von dotchart mit glänzenden

output$savePlotAmount <- downloadHandler(
    filename = "amount.png", 
    content = function(file) { 
     if(input$plotType == "dot"){ 
     png(file = file) 
     plotAmount() 
     dev.off() 
     }else{ 
     ggsave(plotAmount(), filename = file) 
     } 

    }) 

Ich verbrachte "Stunden" mit dem Versuch, es zu reparieren, aber ich weiß nicht, was los ist. Sorry, dass das Beispiel nicht reproduzierbar ist, aber es ist zu schwer, alle App zu reproduzieren.

EDIT: Was ist plotAmount():

plotAmount <- reactive({ 
    if(input$plotType == "violin") { 
     plotAmount <- ggplot(values$x, aes_string(x = input$groupedBy, y = input$yVariableContinous)) + 
     geom_violin() + 
     ggtitle(paste0(input$yVariableContinous, " grouped by ", input$groupedBy)) + 
     scale_y_continuous(limits = c(0, quantile(values$x[,input$yVariableContinous] , 0.95, na.rm = T))) 
    } 
    if(input$plotType == "boxplot") { 
     plotAmount <- ggplot(values$x, aes_string(x = input$groupedBy, y = input$yVariableContinous)) + 
     geom_boxplot(outlier.shape = NA) + 
     ggtitle(paste0(input$yVariableContinous, " grouped by ", input$groupedBy)) + 
     scale_y_continuous(limits = c(0, quantile(values$x[,input$yVariableContinous] , 0.95, na.rm = T))) 
    } 
    if(input$plotType == "dot") { 
     var <- ifelse(input$groupedBy == 1, input$xVariable, input$groupedBy) 
     agregat <- aggregate(x = values$x[,input$yVariableContinous], by = list(g = values$x[,var], xx = values$x[,input$xVariable]), FUN = input$valueAs) 
     dotchart(agregat$x, labels = agregat$xx, 
       groups = as.factor(agregat$g), 
       color = brewer.pal(9,"Set1")[as.numeric(as.factor(agregat$g))], 
       xlab = "salary", 
       cex = .75, 
       main = paste0(input$yVariableContinous, " for ", input$xVariable, 
          "\ngrouped by ", input$groupedBy), 
       xlim = c(min(values$x[,input$yVariableContinous], na.rm = T), quantile(values$x[,input$yVariableContinous] , 0.95, na.rm = T)), 
       pch = 16 
    ) 
    } 

Antwort

0

ggplot2 Plots sein müssen print() machen d zu‘.

+0

Hier ist der erste Teil in 'png (Datei = Datei)' nicht ggplot. Es ist ein Punktdiagramm - das gleiche wie das grundlegende 'plot()'. Und die zweite in 'gsave (...' funktioniert gut. –

+0

'plotAmount()' ist ein ggplot-Objekt, richtig? Probieren Sie eine 'print (plotAmount())'. Siehe https://www.rdocumentation.org/packages /ggplot2/versions/2.2.1/topics/print.gplot –

+0

nein, wenn 'input $ plotType ==" dot "' dann ist es 'dotchart()' was ist das gleiche wie 'plot()' wenn nicht dann es ist ggplot. Ich habe den Code 'plotAmount()' –

Verwandte Themen