2016-06-14 2 views
0

hola私は何かに立ち往生しています。私はggplot2 Shinyアプリケーションを作成しています。ここで、ユーザーは折れ線グラフに表示される変数の量を選択できます。複数の変数が選択されている場合、アプリケーションがクラッシュしたが、私はエラーを取得し、selectInputの引数の複数を使用:ggplotの光沢のあるアプリに可変量の線を表示する

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:

Warning: Error in .subset2: subscript out of bounds 

ここdata

サーバーは次のようになります。

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") 
     ) 
    ) 
    ) 
)) 

ありがとうございます

+0

私の研究から、私は多分、私が代わりの観察反応性表現が必要だと思います。それらを交換することはできませんでした。 –

+0

月ごとに異なる行のプロットが必要ですか? – aosmith

+0

はい、私はグラフ上にあるかどうかを選択します。 –

答えて

0

dcast_off[[monthBy_off]]は1つの値でしか動作せず、input$monthにはmultiple=TRUEが1か月以上選択できるのでチャーターのベクトルが含まれています。

エラーを削除するには、次の構文を使用する必要があります。trick_off <- dcast_off[,monthBy_off]

しかし、プロットエラーを修正する必要があります。たとえば、毎月別の色でプロットします。このためには、より良い(dcast()前)長いdata.frameを使用したい:

server <- shinyServer(function(input, output, session) { 
     observe({ 

       trick_off <- dat_off[dat_off$variable %in% input$month,] 
       output$plot_off <- renderPlot({ 
         O <-ggplot(data = trick_off, aes(x=time_,y=value, color=variable)) + 

           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 
       }) 

     }) 

}) 

enter image description here

+0

それは途中で素晴らしいです。したがって、入力$ monthはUIからの入力を取得し、すべてが入力に対応する 'dat_off $ variable'の行を選択します。列がある場合はデータフレームなので、 'data = trick_off'が動作し、そこにx、y、colorの各列を割り当てることができますか?だから、グループの議論ではないにしても、別々の月を分けて保存していますか?申し訳ありません、すべての質問については、私はちょうどこの作品のいくつかを理解しようとしています/ –

+0

'color = variable'と書くと' ggplot() 'にいくつかのシリーズがあります。 – HubertL

関連する問題