【问题标题】:Shiny R Update a list box after confirming deleteShiny R 确认删除后更新列表框
【发布时间】:2016-11-23 15:35:17
【问题描述】:

这可能是关于shiny 的一个非常基本的问题 我有一个下拉列表,用户单击一个按钮,下拉菜单应更新为少一个项目

这是一个玩具示例

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 中的存储过程会将数据移动到另一个表,并且列表框应该更新以删除列表框中的数据,因为它不再需要被批准

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    使用 reactiveValues 和 updateSelectInput 来改变 Select Input。

    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
        )
    
    })   
    }
    

    【讨论】:

    • 谢谢@Icaro Bombonato,我没有意识到这是一个选项
    猜你喜欢
    • 1970-01-01
    • 2018-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多