这可能是关于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中的存储过程将数据移动到另一个表并且列表框应该更新从列表框中删除数据,因为它不再需要被批准
答案 0 :(得分:3)
使用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
)
})
}