Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R:闪亮的;“全部”;单选按钮_R_Shiny - Fatal编程技术网

R:闪亮的;“全部”;单选按钮

R:闪亮的;“全部”;单选按钮,r,shiny,R,Shiny,我成功地启动了以下代码,为单选按钮输出两个选项:“否”和“是”。但是,我想添加第三个单选按钮,称之为“全部”,它在一个输出中同时显示“否”和“是”的值 我该怎么做呢 library(shiny) library(ggplot2) library(dplyr) bcl <- read.csv("testd10Apr2017V4.csv", sep = ",", stringsAsFactors = FALSE) ui <- fluidPage( titlePanel("Attr

我成功地启动了以下代码,为单选按钮输出两个选项:“否”和“是”。但是,我想添加第三个单选按钮,称之为“全部”,它在一个输出中同时显示“否”和“是”的值

我该怎么做呢

library(shiny)
library(ggplot2)
library(dplyr)

bcl <- read.csv("testd10Apr2017V4.csv", sep = ",", stringsAsFactors = FALSE)

ui <- fluidPage(
  titlePanel("Attrition VS Age"),
  sidebarLayout(
    sidebarPanel(
#      sliderInput("priceInput", "Price", 0, 100, c(25, 40), pre = "$"),
      radioButtons("typeInput", "Type",
                   choices = c("No", "Yes", "All"),
                   selected = "Yes", inline = TRUE, width = "200px"),
      hr(),
      helpText("Attrition no means there is no attrition")
#     selectInput("countryInput", "Country",
#                 choices = c("CANADA", "FRANCE", "ITALY"))
    ),
    mainPanel(
      plotOutput("coolplot")
#      br(), br(),
#      tableOutput("results")
    )
  )
)

server <- function(input, output) {
  output$coolplot <- renderPlot({
    filtered <-
      bcl %>%
      filter(#Price >= input$priceInput[1],
             #Price <= input$priceInput[2],
             Type == input$typeInput
#             Country == input$countryInput
      )
    g <- ggplot(filtered, aes(Age)) +
      geom_histogram(color = "white", fill = "maroon")
    g + ylim(0,30) + xlim(0,60)
    g
  })
}

shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(GG2)
图书馆(dplyr)

bcl我没有运行代码,因为我没有数据文件,但是类似的东西应该适合您。 在服务器功能中,您可以添加如下内容:

if (input$typeInput == "All"){
    filtered <- bcl
} else {
    filtered <- bcl %>% 
      filter(Type == input$typeInput)
}
if(输入$typeInput==“全部”){
过滤