0

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

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 

用户界面

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

服务器.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 应用程序启动时显示。当用户切换输入选项时,我看不到错误消息。

4

0 回答 0