2017-09-11 19 views
1

私はShiny Rを初めて使用しています。プロジェクトの一環として、選択リストで選択するために別個の値を表示する必要がありますが、照会する「すべて」というオプションデータセットから値の選択リストにユーザー定義値を追加する方法

dataset <- read.csv("dataset.csv", header=TRUE) 
fluidPage(
    title = "ABC XYZ", 
    hr(), 
    fluidRow(
    titlePanel("ABC XYZ"), 
    sidebarPanel(
selectInput("region", label = "Region", 
      choices = unique(dataset$region), 
      selected = 1) 
) 
) 

私は同じことを達成するのを手助けできます。

ありがとうございます。

答えて

2

我々はupdateSelectInput

library(shiny) 
library(DT) 
library(dplyr) 

#using a reproducible example 
dataset <- iris 
allchoice <- c("All", levels(dataset$Species)) 

-ui

ui <- fluidPage(
    title = "ABC XYZ", 
    hr(), 
    fluidRow(
    titlePanel("ABC XYZ"), 
    sidebarPanel(
     selectInput("species", label = "Species", 
        choices = allchoice, multiple = TRUE), 
       verbatimTextOutput("selected") 
    ), 
    mainPanel(dataTableOutput('out'))) 
) 

-server

server <- function(input, output, session) { 
    observe({ 
    if("All" %in% input$species) { 
     selected <- setdiff(allchoice, "All") 
     updateSelectInput(session, "species", selected = selected)  

     } 
    }) 

output$selected <- renderText({ 
    paste(input$species, collapse = ", ") 

}) 

output$out <- renderDataTable({ 
    dataset %>% 
      filter(Species %in% input$species)  

}) 

-runアプリでchoicesおよび更新に追加levelまたはunique要素 'すべて' を作成することができます

shinyApp(ui, server) 

enter image description here

enter image description here

関連する問題