2017-11-09 8 views
0

selectInputを '書き込み可能'に変更したいです。たとえば、 'location'にはアムステルダム、ロッテルダム、デンハーグなどがあります。私は '書き込み可能'なinputselectorを実装したいと思います。だから誰かが "Ams .."や "Amster ..."と書いたときに、この基準に合致する可能性のある場所が表示されます。 誰か助けてくれますか?前もって感謝します。書き込み可能なselectInputセレクタ

これは私の単純化されたUIセクションです:

library(DT) 
library(shiny) 
library(shinydashboard) 

Location = c("Amsterdam","Amsterdam","Amsterdam","Rotterdam","Rotterdam","Rotterdam","Den Haag","Den Haag","Den Haag") 
Year = c(2015,2014,2016,2015,2016,2016,2017,2016,2014) 
Person = c("John", "Ann", "Katy", "Ann", "Katy", "William", "Henry", "Luke", "Luke") 
mockup = data.frame(Location, Year, Person) 

ui <- dashboardPage(
        dashboardHeader(), 
        dashboardSidebar(
         sidebarMenu(
         menuItem("Selection", tabName = "selection")     
           ) 
        ), 
        dashboardBody(
         tabItems(
         tabItem(tabName = "selection", 
           fluidRow(
            box(width = 5, 
             title = "TITLE", "Choose something", 
             collapsible = FALSE, 
             htmlOutput("Location_selector"), 
             htmlOutput("Year_selector") 
           ), 
            mainPanel(
            DT::dataTableOutput("selection") 
           ) 
           ))    

             ) 
        ) 
        ) 

と、これは私のサーバーセクションです:

server <- function(input, output, session) { 

    output$Location_selector = renderUI({ 
    selectInput(inputId = "Location", 
       label = "Location:", 
       choices = sort(as.character(unique(mockup$Location)))) 
    }) 
    output$Year_selector = renderUI({ 

    data_available = mockup[mockup$Location == input$Location, "Year"] 

    selectInput(inputId = "Year", 
       label = "Year:", 
       choices = sort(unique(data_available)), 
       selected = unique(data_available)[1]) 
    }) 

} 

shinyApp(ui, server) 

答えて

0

私はここSO上の自分の質問への答えを見つけました。空のオプション( "")を追加して、サーバーセクションの「選択肢」部分を調整しました。

server <- function(input, output, session) { 

    output$Location_selector = renderUI({ 
    selectInput(inputId = "Location", 
       label = "Location:", 
       choices = c("", (sort(as.character(unique(mockup$Location)))))) 
    }) 
} 

shinyApp(ui, server) 
関連する問題