2016-04-01 19 views
1

ich eine glänzende App mit dem folgenden Code erstellt haben:Shiny App nicht ausgegeben ändert sich je nach dem Eingang

library(shiny) 
ui <- fluidPage(
    selectInput("mr", 
       label="Type of Merchandise", 
       choices=c("Groceries", "WhiteGoods", "HomeGoods","Clothes"), 
       selected="Groceries"), 
    plotOutput("curv") 
) 

server <- function(input, output){ 
    output$curv <- renderPlot({ 
    ggplot(new, aes(x=Year, y=Sales, colour = input$mr)) + 
     geom_point(alpha=.3) + 
     geom_smooth(alpha=.2, size=1) + 
     ggtitle("Fitted curve for overall sales") 
    }) 
} 

shinyApp(ui = ui, server = server) 

Wenn ich den Code ausführen, es gibt mir eine statische Handlung und nach nicht zur Eingabe ändern . Was ich versuche zu erreichen ist, wenn die Eingabe "Lebensmittel" ist, sollte das Diagramm Verkaufsdaten für diese Eingabe anzeigen. Aber in diesem Fall wird es nicht aktualisiert. Hier ist der Screenshot der Ausgabe: enter image description here

Der Datensatz ich benutze ist:

structure(list(Merchandise = structure(c(4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 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, 7L, 
8L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L, 2L, 
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 
8L, 9L, 10L), .Label = c("Shop01", "Shop02", "Shop03", "Shop04", 
"Shop05", "Shop06", "Shop07", "Shop08", "Shop09", "Shop10"), class = "factor"), 
    Year = c(2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
    2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
    2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
    2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
    2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2014L, 2014L, 2014L, 
    2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 
    2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 
    2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 
    2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 
    2014L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
    2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
    2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
    2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
    2013L, 2013L, 2013L, 2013L, 2013L, 2012L, 2012L, 2012L, 2012L, 
    2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 
    2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 
    2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 
    2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 
    2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 
    2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 
    2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 
    2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 
    2011L, 2011L, 2011L, 2011L), Total.Sales = c(45547000, 28775000, 
    17029000, 28827000, 38929000, 10740000, 15008000, 10013000, 
    14556000, 10669000, 14334000, 6521000, 30025000, 5899000, 
    5333919, 1915000, 8312000, 4053000, 3506000, 3492000, 11601000, 
    7730000, 7519000, 14426000, 7046000, 1875000, 7902000, 6775000, 
    6063000, 15843000, 19047000, 8250000, 21218000, 7161000, 
    6812000, 1728000, 9807000, 5543000, 5012000, 4790000, 71817000, 
    43940000, 35523000, 56430000, 70254000, 19149000, 28253000, 
    133249000, 27730000, 25198000, 15233000, 10179000, 24703000, 
    9482000, 8850000, 2800000, 11749000, 8734000, 7753000, 7698000, 
    10135000, 9094000, 8669000, 11978000, 8438000, 2391000, 9526000, 
    7978000, 8791000, 13948000, 18087000, 8626000, 21835000, 
    6935000, 6134000, 2380000, 9306000, 5787000, 4388000, 4755000, 
    80738000, 43987000,00, 54873000, 73234000, 18765000, 
    38748000, 103439000, 36943000, 27176000, 12348000, 95600000, 
    18047000, 9104000, 8190000, 2096000, 9719000, 7557000, 7503000, 
    6918000, 7530000, 5456000, 5452000, 7459000, 5218000, 1615000, 
    5613000, 4532000, 4147000, 6534000, 18168000, 7462000,00, 
    5819000, 5733269, 1994284, 8622000, 5745984, 4532426, 4395000, 
    71823000, 38904000, 35842000, 57027000, 52850000, 19012000, 
    28645000, 0, 0, 0, 10408000, 7429000, 10915000, 6997000, 
    5571000, 1559000, 8543000, 0, 0, 0, 7314000, 5396000, 5041000, 
    9620000, 4468000, 1304000, 5426000, 0, 0, 0, 13694000, 7615000, 
    20337000, 7569000, 6201000, 135200, 8673000, 0, 0, 0, 65325000, 
    47179000, 29659000, 37861000, 58183000, 16129000, 23828000, 
    0, 0, 0, 13237000, 8825000, 13981000, 7841000, 4597000, 1155589, 
    13109000, 0, 0, 0, 6412000, 4998000, 4776000, 8306000, 5749000, 
    1539000, 6013000, 0, 0, 0, 16683000, 6223000, 17941000, 5740000, 
    4019000, 1453000, 7130000, 0, 0, 0), Latitude = c(-37.8594, 
    -37.8532, -38.3697, -34.3698, -33.4187, -31.0025, -28.8214, 
    -42.8826, -27.405, -28.0632, -37.8594, -37.8532, -38.3697, 
    -34.3698, -33.4187, -31.0025, -28.8214, -42.8826, -27.405, 
    -28.0632, -37.8594, -37.8532, -38.3697, -34.3698, -33.4187, 
    -31.0025, -28.8214, -42.8826, -27.405, -28.0632, -37.8594, 
    -37.8532, -38.3697, -34.3698, -33.4187, -31.0025, -28.8214, 
    -42.8826, -27.405, -28.0632, -37.8594, -37.8532, -38.3697, 
    -34.3698, -33.4187, -31.0025, -28.8214, -42.8826, -27.405, 
    -28.0632, -37.8594, -37.8532, -38.3697, -34.3698, -33.4187, 
    -31.0025, -28.8214, -42.8826, -27.405, -28.0632, -37.8594, 
    -37.8532, -38.3697, -34.3698, -33.4187, -31.0025, -28.8214, 
    -42.8826, -27.405, -28.0632, -37.8594, -37.8532, -38.3697, 
    -34.3698, -33.4187, -31.0025, -28.8214, -42.8826, -27.405, 
    -28.0632, -37.8594, -37.8532, -38.3697, -34.3698, -33.4187, 
    -31.0025, -28.8214, -42.8826, -27.405, -28.0632, -37.8594, 
    -37.8532, -38.3697, -34.3698, -33.4187, -31.0025, -28.8214, 
    -42.8826, -27.405, -28.0632, -37.8594, -37.8532, -38.3697, 
    -34.3698, -33.4187, -31.0025, -28.8214, -42.8826, -27.405, 
    -28.0632, -37.8594, -37.8532, -38.3697, -34.3698, -33.4187, 
    -31.0025, -28.8214, -42.8826, -27.405, -28.0632, -37.8594, 
    -37.8532, -38.3697, -34.3698, -33.4187, -31.0025, -28.8214, 
    -42.8826, -27.405, -28.0632, -37.8594, -37.8532, -38.3697, 
    -34.3698, -33.4187, -31.0025, -28.8214, -42.8826, -27.405, 
    -28.0632, -37.8594, -37.8532, -38.3697, -34.3698, -33.4187, 
    -31.0025, -28.8214, -42.8826, -27.405, -28.0632, -37.8594, 
    -37.8532, -38.3697, -34.3698, -33.4187, -31.0025, -28.8214, 
    -42.8826, -27.405, -28.0632, -37.8594, -37.8532, -38.3697, 
    -34.3698, -33.4187, -31.0025, -28.8214, -42.8826, -27.405, 
    -28.0632, -37.8594, -37.8532, -38.3697, -34.3698, -33.4187, 
    -31.0025, -28.8214, -42.8826, -27.405, -28.0632, -37.8594, 
    -37.8532, -38.3697, -34.3698, -33.4187, -31.0025, -28.8214, 
    -42.8826, -27.405, -28.0632, -37.8594, -37.8532, -38.3697, 
    -34.3698, -33.4187, -31.0025, -28.8214, -42.8826, -27.405, 
    -28.0632), Longitude = c(144.7994, 147.5463, 142.4617, 150.6471, 
    149.5702, 150.1511, 153.26, 147.3216, 152.4424, 148.2859, 
    144.7994, 147.5463, 142.4617, 150.6471, 149.5702, 150.1511, 
    153.26, 147.3216, 152.4424, 148.2859, 144.7994, 147.5463, 
    142.4617, 150.6471, 149.5702, 150.1511, 153.26, 147.3216, 
    152.4424, 148.2859, 144.7994, 147.5463, 142.4617, 150.6471, 
    149.5702, 150.1511, 153.26, 147.3216, 152.4424, 148.2859, 
    144.7994, 147.5463, 142.4617, 150.6471, 149.5702, 150.1511, 
    153.26, 147.3216, 152.4424, 148.2859, 144.7994, 147.5463, 
    142.4617, 150.6471, 149.5702, 150.1511, 153.26, 147.3216, 
    152.4424, 148.2859, 144.7994, 147.5463, 142.4617, 150.6471, 
    149.5702, 150.1511, 153.26, 147.3216, 152.4424, 148.2859, 
    144.7994, 147.5463, 142.4617, 150.6471, 149.5702, 150.1511, 
    153.26, 147.3216, 152.4424, 148.2859, 144.7994, 147.5463, 
    142.4617, 150.6471, 149.5702, 150.1511, 153.26, 147.3216, 
    152.4424, 148.2859, 144.7994, 147.5463, 142.4617, 150.6471, 
    149.5702, 150.1511, 153.26, 147.3216, 152.4424, 148.2859, 
    144.7994, 147.5463, 142.4617, 150.6471, 149.5702, 150.1511, 
    153.26, 147.3216, 152.4424, 148.2859, 144.7994, 147.5463, 
    142.4617, 150.6471, 149.5702, 150.1511, 153.26, 147.3216, 
    152.4424, 148.2859, 144.7994, 147.5463, 142.4617, 150.6471, 
    149.5702, 150.1511, 153.26, 147.3216, 152.4424, 148.2859, 
    144.7994, 147.5463, 142.4617, 150.6471, 149.5702, 150.1511, 
    153.26, 147.3216, 152.4424, 148.2859, 144.7994, 147.5463, 
    142.4617, 150.6471, 149.5702, 150.1511, 153.26, 147.3216, 
    152.4424, 148.2859, 144.7994, 147.5463, 142.4617, 150.6471, 
    149.5702, 150.1511, 153.26, 147.3216, 152.4424, 148.2859, 
    144.7994, 147.5463, 142.4617, 150.6471, 149.5702, 150.1511, 
    153.26, 147.3216, 152.4424, 148.2859, 144.7994, 147.5463, 
    142.4617, 150.6471, 149.5702, 150.1511, 153.26, 147.3216, 
    152.4424, 148.2859, 144.7994, 147.5463, 142.4617, 150.6471, 
    149.5702, 150.1511, 153.26, 147.3216, 152.4424, 148.2859, 
    144.7994, 147.5463, 142.4617, 150.6471, 149.5702, 150.1511, 
    153.26, 147.3216, 152.4424, 148.2859)), .Names = c("Merchandise", 
"Stores", "Year", "Total.Sales", "Latitude", "Longitude"), row.names = c(NA, 
-200L), class = "data.frame") 

Bin ich etwas fehlt aus dem Code? Jede Hilfe hier wird sehr geschätzt.

+0

Sie haben Ihre Daten nicht nach Eingabe gefiltert, daher werden immer alle Verkaufsdaten geplottet. –

+0

Vielen Dank für Ihre Antwort. Wo füge ich den Filter hinzu? Tut mir leid, ich bin neu in diesem Bereich. –

Antwort

1

Hier ist eine funktionierende Version. new[new$Merchandise==input$mr,] filtert die Daten entsprechend Ihrer Auswahl. Auch einige der Spaltennamen stimmen nicht überein und ich habe sie geändert.

library(shiny) 
library(ggplot2) 

ui <- fluidPage(
    selectInput("mr", 
       label="Type of Merchandise", 
       choices=c("Groceries", "White goods", "Home goods","Clothes"), 
       selected="Groceries"), 
    plotOutput("curv") 
) 

server <- function(input, output){ 

    output$curv <- renderPlot({ 
     ggplot(new[new$Merchandise==input$mr,], aes(x=Year, y=Total.Sales)) + 
      geom_point(alpha=.3) + 
      geom_smooth(alpha=.2, size=1) + 
      ggtitle("Fitted curve for overall sales") 
    }) 
} 

shinyApp(ui = ui, server = server) 
+0

Danke für die Eingabe. Allerdings bekomme ich jetzt eine leere Handlung. Gibt es irgendetwas, was ich tun sollte? –

+0

Es funktioniert hier richtig. Wird Ihr Datenrahmen als "neu" bezeichnet und korrekt gelesen? Und stellen Sie sicher, dass die Spaltennamen übereinstimmen. –

+0

Wird einfach durch Ausführen von 'new' überprüft und es werden die darin enthaltenen Daten angezeigt. Die Spaltennamen stimmen auch überein. Ich weiß nicht, warum es mir immer noch eine graue leere Handlung gibt. –

Verwandte Themen