Co powstrzymuje moją małą błyszczącą aplikację od wyświetlania mojego ggplota? Kiedy zamieniam kod w renderPlot() na przykład przy użyciu funkcji wykresu podstawowego, pojawia się on razem. Używam RStudio, R v3.0.1 w systemie Windows Vista, wyprowadzam do przeglądarki Chrome.Shiny nie wyświetla mojego ggplot, jak się spodziewałem
ui.r
library(ggplot2)
cities <- c("Anchorage","Fairbanks","Juenau","Wasilla","Homer")
years <- 2003:2013
Table <- "Capital Assets"
Account <- c("Land", "Art", "Buildings", "Equipment")
dat <- data.frame(City = sort(rep(cities, length(years))), Year = rep(years,length(cities)), Table)
sampleDat <- rbind(data.frame(dat,Acount = Account[1]), data.frame(dat, Acount = Account[2]), data.frame(dat, Acount = Account[3]), data.frame(dat, Acount = Account[4]))
finalDat <- data.frame(sampleDat, Value = runif(length(sampleDat[,1]), 1000,10000))
shinyUI(pageWithSidebar(
headerPanel("CAFR Explorer"),
selectInput("city","City", as.list(levels(finalDat$City)), selected = NULL, multiple = FALSE),
mainPanel(
h3(textOutput("caption")),
plotOutput("CAFRplot")
)))
server.r
library(shiny)
library(ggplot2)
cities <- c("Anchorage","Fairbanks","Juenau","Wasilla","Homer")
years <- 2003:2013
Table <- "Capital Assets"
Account <- c("Land", "Art", "Buildings", "Equipment")
dat <- data.frame(City = sort(rep(cities, length(years))), Year = rep(years,length(cities)), Table)
sampleDat <- rbind(data.frame(dat,Acount = Account[1]), data.frame(dat, Acount = Account[2]), data.frame(dat, Acount = Account[3]), data.frame(dat, Acount = Account[4]))
finalDat <- data.frame(sampleDat, Value = runif(length(sampleDat[,1]), 1000,10000))
shinyServer(function(input, output) {
formulaText <- reactive({
paste(input$city)
})
output$caption <- renderText({
formulaText()
})
output$CAFRplot <- renderPlot({
## this one isn't working.
ggplot(finalDat, aes(x = finalDat[which(finalDat$City == input$city),2],
y = finalDat[which(finalDat$City == input$city),5])) +
geom_point()
## this one is working
#plot(finalDat[which(finalDat$City == input$city),2], y = finalDat[which(finalDat$City == input$city),5])
})
})
spróbować owijania ty ggplot zadzwonić 'print' czyli' print (ggplot (...) + geom_point) ' –
Należy pokazać pojawia się komunikat o błędzie zamiast mówić "nie działa". Jake ma rację, że powinieneś owijać wydruk wokół twojego połączenia ggplot, ale myślę, że jest coś jeszcze nie tak z twoją rozmową ggplot (problem z zakresu). – GSee