我一直在尝试在shiny上使用selectInput来选择我想要绘制的向量的值。
在本例中,我想使用selectInput在我想要子集的向量之间进行选择。如果我选择Grey,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)发布于 2019-12-31 01:52:56
input$input1是一个字符串。
而不是:
df <- df[input$input1 != "big",]尝试:
df <- df[which(df[[input$input1]] != "big"),]https://stackoverflow.com/questions/59534744
复制相似问题