【发布时间】:2020-03-21 08:03:22
【问题描述】:
我正在尝试将selectInput 与 Null 选项集成,以便我可以按运动员在 NBA 的第一年进行过滤,但是当我运行该应用程序时,图表将无法加载。
这是我的代码的精简版:
ui <- fluidPage(
titlePanel(title = h4("NBA StatsR", align = "center")),
tabsetPanel(type = "tabs",
tabPanel("NBA 2019-2020",
sidebarLayout(
sidebarPanel(
selectInput(inputId = "Draft Class",
label = "DraftClass",
choices = c("NULL","2007"),
selected = NULL)
),
mainPanel(
plotOutput(outputId = "plot4", width = "104%",
height = "500px")
)))))
server <- function(input, output, session) {
output$plot4 <- renderPlot({
listVal <- reactive({
if (is.null(input$DraftClass)){
"yearSeasonFirst"}
else {
input$DraftClass}
})
NBA1920withLuka %>%
filter(minutesPerGame >= 15) %>%
filter(ratioPER >= 10) %>%
filter(countGames >= 9) %>%
filter(yearSeasonFirst == listVal()) %>%
top_n(10, get(input$select4)) %>%
ggplot(aes(x = reorder(namePlayer,
ptsPerGame),
y = ptsPerGame)) +
geom_bar(stat = "identity")
})
}
解决方案:Johnson,这是一个打开和关闭的案例。我的 selectInput id 是“Draft Class”,但我将其称为 DraftClass,没有空格。但是,我发现即使使用其他解决方法(如此处和其他地方所建议的那样),它们也不会输出 filter(yearSeasonFirst == yearSeasonFirst) 的任何内容
所以我尝试了一个 if else,如果 input$DraftClass == 我想要的 null 选项,运行输出代码而不使用 yearSeasonFirst 的过滤器
【问题讨论】:
-
你不应该把你的反应列表放在你的渲染图中。无论如何,问题是 NULL 不会触发 listVal 的反应。尝试将 ignoreNULL 设置为 FALSE 的 `eventReactive。