首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用selectInput选择向量

使用selectInput选择向量
EN

Stack Overflow用户
提问于 2019-12-31 01:38:35
回答 1查看 134关注 0票数 0

我一直在尝试在shiny上使用selectInput来选择我想要绘制的向量的值。

在本例中,我想使用selectInput在我想要子集的向量之间进行选择。如果我选择Grey,df应该只选择灰色向量上不大的观测值。

我不能让它工作。我该怎么办?

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-12-31 01:52:56

input$input1是一个字符串。

而不是:

代码语言:javascript
复制
df <- df[input$input1 != "big",]

尝试:

代码语言:javascript
复制
df <- df[which(df[[input$input1]] != "big"),]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59534744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档