警告:data.frame中的错误:参数表示行数不同:10、0-数据帧创建问题

时间:2019-04-12 20:56:41

标签: r shiny shiny-server shinyapps

我正在尝试创建一个数据框,并且该数据框的创建如下:

2005 40.96250 40.73171
2006 40.77922 41.38596
2007 38.92683 40.76829
2008 36.09756 39.54430
2009 38.83562 37.97368
2010 33.89024 35.47222
2011 38.48276 35.45000
2012 38.62821 36.69444
2013 29.50000 32.59494
2014 34.48571 34.88750

但是我在控制台中收到以下错误消息。

  

“警告:data.frame中的错误:参数暗示不同数量的   行:10,0“

我尝试了以下代码并收到了错误消息

a<- Seasons

 b <-  MinutesPlayed[rownames(MinutesPlayed) %in% 
 c(input$player1)]/Games[rownames(Games) %in% c(input$player1)]

 c <-  MinutesPlayed[rownames(MinutesPlayed) %in% 
 c(input$player2)]/Games[rownames(Games) %in% c(input$player2)]

plotdata <- data.frame(a,b,c)

用于创建数据框的数据

Seasons <- c("2005","2006","2007","2008","2009","2010","2011","2012","2013","2014")

分钟播放矩阵如下(数据):

              2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 
    KobeBryant 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000
    JoeJohnson 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000
   LeBronJames 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000
CarmeloAnthony 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000
  DwightHoward 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000
    ChrisBosh  1000 1000 1000 1000 1000 1000 1000 1000 1000 1000
    ChrisPaul  3000 3000 3000 3000 3000 3000 3000 3000 3000 3000
   KevinDurant 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000
   DerrickRose 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000

游戏矩阵如下(数据):

             2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 
    KobeBryant 50   50   50   50   50   50   50   50   50   50
    JoeJohnson 50   50   50   50   50   50   50   50   50   50
   LeBronJames 50   50   50   50   50   50   50   50   50   50
CarmeloAnthony 50   50   50   50   50   50   50   50   50   50
  DwightHoward 50   50   50   50   50   50   50   50   50   50
    ChrisBosh  50   50   50   50   50   50   50   50   50   50
    ChrisPaul  50   50   50   50   50   50   50   50   50   50
   KevinDurant 50   50   50   50   50   50   50   50   50   50
   DerrickRose 50   50   50   50   50   50   50   50   50   50

其中 input $ player1和input $ player2是用户在selectInput选项中选择的玩家。

selectInput都具有以下播放器:

   KobeBryant 
    JoeJohnson
   LeBronJames 
CarmeloAnthony 
  DwightHoward 
    ChrisBosh  
    ChrisPaul  
   KevinDurant
   DerrickRose 

UI.R

shinyUI(fluidPage(


      dashboardPage(
        skin='blue',
        dashboardHeader(title = "Players"),
        sidebar =  dashboardSidebar(
          width = 230,
          sidebarMenu(
            sidebarMenu(
              selectInput(inputId="player1", label="Player 1", choices=as.character(Players), selected = NULL, multiple = FALSE),
              uiOutput('player2')         
            )
          )))

SERVER.R

shinyServer(function(input, output) {

  output$player2 = renderUI({
    selectInput(inputId="player2", label="Player 2", choices=as.character(Players[Players != input$player1]), selected = input$player2, multiple = FALSE)
  })
  output$minutes <- renderPlot({
    a<- Seasons
    b <-  MinutesPlayed[rownames(MinutesPlayed) %in% c(input$player1)]/Games[rownames(Games) %in% c(input$player1)]
    c <-  MinutesPlayed[rownames(MinutesPlayed) %in% c(input$player2)]/Games[rownames(Games) %in% c(input$player2)]
    plotdata <- data.frame(a,b,c)
})
})
  

仅当Shiny应用程序显示错误消息   启动时,我没有看到错误消息   由用户切换。

0 个答案:

没有答案