我一直在尝试使用闪亮的 selectInput 来选择我想要绘制的向量的值。
在此示例中,我想使用 selectInput 在要子集的向量之间进行选择。如果我选择灰色,df 应该只选择灰色向量上不大的观察值。
我无法让它工作。我应该怎么办?
library(shiny)
ui <- fluidPage(
titlePanel("Test"),
sidebarLayout(
sidebarPanel(
selectInput("input1",
"Input",
choices = c(
"Blue" = "blue",
"Grey" = "grey",
"Orange" = "orange"
))
),
mainPanel(
plotOutput("plot")
)
)
)
server <- function(input, output) {
blue <- c("big", "small", "big", "small", "medium")
grey <- c("small", "big", "big", "medium", "medium")
orange <- c("big", "big", "medium", "medium", "medium")
big <- c("true", "true", "true", "false", "false")
df<- data.frame(blue, grey, orange, big)
output$plot <- renderPlot({
df <- df[input$input1 != "big",]
plot <- ggplot(df, aes(x=big))+geom_bar()
return(plot)
})
}
shinyApp(ui = ui, server = server)