Ich versuche, ein Grundstück mit ggplot2 für die folgenden Daten zu machen: dataR Shiny: Warum funktioniert ggplot nicht?
Name date weight height
Cat1 2016-03-01 34.20000 22.50000
Cat1 2016-04-01 35.02080 23.01750
Cat1 2016-05-01 35.86130 23.54690
Cat1 2016-06-01 36.72197 24.08848
Cat2 2016-03-01 33.55000 22.96000
Cat2 2016-04-01 33.61710 23.41920
Cat2 2016-05-01 33.68433 23.88758
Cat2 2016-06-01 33.75170 24.36534
Der Code Ich verwende:
library("shiny")
library("xlsx")
library("ggplot2")
animal <- read.xlsx("C:\\data\\animals.xlsx",1)
ui<- fluidPage(
titlePanel("Animals"),
sidebarLayout(
sidebarPanel(
helpText("Create graph of height or weight animals"),
selectInput("anim",
label = "Choose an animal",
choices = c("Cat1", "Cat2"),
selected = "Cat1"),
selectInput("opti",
label = "Option",
choices = c("weight", "height"),
selected = "weight")
),
mainPanel(plotOutput("graph"))
))
server <- function(input, output){
output$graph <- renderPlot({
p2 <- ggplot(subset(animal, Name %in% input$anim)) + geom_line(aes(x=date, y = input$opti))
print(p2)
})
}
shinyApp(ui=ui, server= server)
Ich habe keinen Fehler, aber die Ausgabe des Diagramms ist nur eine gerade Linie (plot). Ich verstehe nicht warum, wenn ich den Code in das Befehlsfenster mit ggplot
setze, funktioniert es.
@jdharrison Nein, sie sind identisch: 'identisch (ggplot2 ::: plot.ggplot, ggplot2 ::: print.ggplot)' → 'TRUE'. –
Vielen Dank für Ihre Antwort! Der Code scheint jedoch immer noch nicht zu funktionieren. Ich bekomme jetzt nur eine leere Handlung ohne eine Linie. – Hav11
Ich denke, es muss aes_string sein? Also versuche genau dasselbe, aber ändere 'aes_' in 'aes_string' – Pete900