hola
我被困在某物上。我正在創建一個ggplot2 Shiny應用程序,用戶可以在其中選擇顯示在折線圖中的變量數量。我用selectInput參數多,但應用程序崩潰時選擇了多個變量,得到錯誤:在ggplot閃亮應用中顯示可變數量的線條
Warning: Error in .subset2: subscript out of bounds
這裏是data
服務器:
library(shiny)
library(googlesheets)
library(reshape2)
library(ggplot2)
library(scales)
#google authorization, token storage, file acquiztion and assignment
myData_off <- melt(ridership_hour_off, id.vars = "time")
dat_off <- myData_off[myData_off$time != "Total",]
dat_off$time_ <- as.POSIXct(paste(dat_off$time), origin = "7:00 AM", format = "%I:%M %p", tz = "UTC")
dcast_off <- dcast(dat_off, time_~variable)
shinyServer(function(input, output, session) {
observe({
monthBy_off <- input$month
trick_off <- dcast_off[[monthBy_off]]
output$plot_off <- renderPlot({
O <-ggplot(data = data.frame(x = dcast_off$time_, y = trick_off), aes(x=x,y=y)) +
geom_line(size = 2, alpha = 0.75) +
geom_point(size =3, alpha = 0.75) +
ggtitle("Boarding the Bus Ridership December 2015") +
labs(x="Time",y="Count")+
theme(plot.title = element_text(family = "Trebuchet MS", color="#666666", face="bold", size=32, hjust=0.5)) +
theme(axis.title = element_text(family = "Trebuchet MS", color="#666666", face="bold", size=22))+
theme_classic()
O
})
})
})
UI:
library(shiny)
vars <- list("December" = "dec",
"January" = "jan",
"February" = "feb",
"March" = "mar",
"April" = "apr",
"May" = "may",
"June" = "jun",
"July" = "jul",
"August" = "aug",
"September" = "sep",
"October" = "oct",
"November" = "nov")
shinyUI(fluidPage(
headerPanel("Cross Acton Transit"),
titlePanel("Data Dashboard"),
# Your input selection
sidebarPanel(
selectInput("month", "Select plot", vars, selected = "apr", multiple = TRUE)
),
# Show the selected plot
mainPanel(
tabsetPanel(
tabPanel("Plot",
plotOutput("plot_off")
)
)
)
))
謝謝您的任何輸入
從我的研究,我想,也許我需要一個反應的表達,而不是觀察。將它們交換不起作用。 –
你想每月有不同線條的情節嗎? – aosmith
是的,我想要選擇哪些線是和不在圖上。 –