长度的参数为零。程序无法识别SelectInput中的选项

时间:2017-01-12 22:56:08

标签: r shiny

ui中的SelectInput函数应该给我一个选择" YES"或"否"。当" NO"如果被选中,它会选择" if((" NO"%in%input $ qualify_pit))"在服务器中的renderDataTable函数中阻塞并完美执行。但是,当我选择" YES"选项,其块不运行,不显示任何表。我尝试了一切来让它运行它的块(if((" YES"%in%input $ qualify_pit)))但无济于事。

library(shiny)
library(shinythemes)
library(DT)

pit <- read.csv("PIT_STAT.csv")

pit_stat <- c("MLB_name","MLBId","LastName","FirstName","LW","W","L","Sv","BS","HLD","G","GS","CG","GF","QS","SHO","IP","BFP","H","X1B","X2B","X3B",
              "HR","R","ER","SH","SF","HBP","BB","IBB","BB_noIBB","K","WP","BLK","GB","FB","LD","POPU","SB",
              "CS","PKO","SVO","OUTS","K9","BB9","AVG","BABIP","HR9","GB_percent","HRperFB","ERA","KperBB",
              "K_percent","BB_percent","K_minus_BB","WHIP","LD_percent","FB_percent","GBperFB")

pit_def <- c("MLB_name","MLBId","LastName","FirstName","LW","W","L","ERA","IP","H","HR","R","ER","BB","K","K9","BB9","HR9","WHIP",
             "GB_percent","FB_percent","LD_percent","K_percent","BB_percent","KperBB","K_minus_BB")

ui <- shinyUI(fluidPage(

  shinythemes::themeSelector(),

  theme = shinytheme("paper"),

  titlePanel("WSFB Stats Lab"),

  fluidRow(
    uiOutput("uis")
  ),

  fluidRow(

    tabsetPanel(id = "tabs",
                tabPanel("Pitch Table",dataTableOutput("pitch_table"))
    )
  )


)
)


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


    output$uis <- renderUI({

      if(input$tabs == "Pitch Table")
      {
        pit <- read.csv("PIT_STAT.csv")

        pit_stat <- c("MLB_name","MLBId","LastName","FirstName","LW","W","L","Sv","BS","HLD","G","GS","CG","GF","QS","SHO","IP","BFP","H","X1B","X2B","X3B",
                      "HR","R","ER","SH","SF","HBP","BB","IBB","BB_noIBB","K","WP","BLK","GB","FB","LD","POPU","SB",
                      "CS","PKO","SVO","OUTS","K9","BB9","AVG","BABIP","HR9","GB_percent","HRperFB","ERA","KperBB",
                      "K_percent","BB_percent","K_minus_BB","WHIP","LD_percent","FB_percent","GBperFB")

        pit_def <- c("MLB_name","MLBId","LastName","FirstName","LW","W","L","ERA","IP","H","HR","R","ER","BB","K","K9","BB9","HR9","WHIP",
                     "GB_percent","FB_percent","LD_percent","K_percent","BB_percent","KperBB","K_minus_BB")

        wellPanel(
          checkboxGroupInput('show_vars', 'Variables to display', pit_stat, inline = TRUE, selected = pit_def),
          selectInput("qualify_pit","MIN IP:",choices = c("YES","NO"))
        )

      }
    })


  output$pitch_table <- renderDataTable({

    if(("YES" %in% input$qualify_pit))
    {
      pit <- read.csv("PIT_STAT.csv")
      pit2 <- pit[pit$IP >= 162,]
      DT::datatable(pit2[,input$show_vars, drop = FALSE])

    }

    if(("NO" %in% input$qualify_pit))
    {
      pit <- read.csv("PIT_STAT.csv")
      DT::datatable(pit[,input$show_vars, drop = FALSE])

    }

  })


})

shinyApp(ui = ui, server = server)

1 个答案:

答案 0 :(得分:0)

它与NO一起使用,因为if("NO" %in%...是函数的最后一个表达式,因此它是隐式返回值。

但对于YES,这不是最后一次评估(return是),您必须明确使用return(DT::datatable(pit2[,input$show_vars, drop = FALSE]))

else

否则您只需使用 output$pitch_table <- renderDataTable({ if(("YES" %in% input$qualify_pit)) { DT::datatable(pit[pit$IP >= 162,input$show_vars, drop = FALSE]) } else { DT::datatable(pit[,input$show_vars, drop = FALSE]) } })

即可
return

有关使用day = datetime.datetime.strptime('12/22/2017', '%m/%d/%Y').strftime('%A') 的详细信息,请参阅this thread