2016-11-23 55 views
1

這可能是關於shiny 一個很基本的問題,我有一個下拉列表,其中用戶點擊一個按鈕,在下拉菜單中應該少了一個項目更新後閃亮[R更新列表框中,確認刪除

這裏有一個玩具的例子

library(shiny) 
library(shinythemes) 

getData<- function() 
{ 
    data <- c('A','B','C','D') 
    return (data) 
} 



ui <- fluidPage(

    selectInput("names", "Select Data", getData(), multiple = FALSE), 
    actionButton("del","delete"), 
    bsModal("modalnew", "Approve Data For Reporting", "del", size = "medium", 
      HTML("Note: Confirm Deletion"), 
      br(),br(), 
      actionButton("delyes", "Yes"), 
      actionButton("delno", "No") 
) 

) 

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

    # Reactive part that gets the data and populates the drop down 
    my_sel = reactive({ 
    mydata = getData() 
    }) 

    # Confirmation Menu to Approve the upload 
    observeEvent(input$delyes, { 
    toggleModal(session, "modalnew", toggle = "close") 

# Delete an Item, Update the list box with one less item 


    }) 

} 

shinyApp(ui = ui, server = server) 

一個項目應該從列表中消失。 我基本上堅持反應位我猜。

在我與玩具示例分開的項目中,用戶通過首先選擇區域來審查其數據,如果他們批准MySQL中的存儲過程,則將數據移動到另一個表,並且列表框應更新爲刪除列表框中的數據,因爲它不再需要批准

回答

2

使用reactiveValues和updateSelectInput更改選擇輸入。

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

# Reactive part that gets the data and populates the drop down 
v <- reactiveValues(
    mydata = getData() 
) 

# Confirmation Menu to Approve the upload 
observeEvent(input$delyes, { 
    toggleModal(session, "modalnew", toggle = "close") 

    # Delete an Item, Update the list box with one less item 
    v$mydata <- v$mydata[!v$mydata %in% input$names] 

    #update the selection 
    updateSelectInput(session, "names", 
         choices = v$mydata 
    ) 

}) 
} 
+0

謝謝@Icaro Bombonato,我沒有意識到這是一個選項 –