对于这个问题,我修改了代码(https://cran.r-project.org/web/packages/shinyjqui/readme/README.html)
我需要重置订单输入的基础上点击按钮“重置”。
示例:如果我将Nov和Dec放到Dest中,然后单击按钮,我希望这些元素再次出现在Source中。我可以按ID调用订单输入来重置它们吗?
server <- function(input, output) {
output$order <- renderPrint({ print(input$dest_order) })
observeEvent(input$btn,{
reset("dest") # these did not work
reset("input$dest")
reset(input$dest)
})
}
ui <- fluidPage(
orderInput('source', 'Source', items = month.abb,
connect = 'dest'),
orderInput('dest', 'Dest', items = NULL, placeholder = 'Drag items here...', connect = 'source'),
verbatimTextOutput('order'),
actionButton("btn","reset")
)
shinyApp(ui, server)发布于 2020-02-28 10:48:59
对于orderInput小部件没有对reset()或updateSelectInput()作出反应,我也有类似的问题。
最后,我使用了一项工作,其中orderInput小部件的ui是重新呈现的,只要按下重置按钮。这是基于另一个堆栈溢出问题(Maximum item in shinyjqui::orderInput)的答案。
如果我正确理解了您的情况,您希望在按下reset按钮时将源orderInput小部件和dest小部件重置为它们的初始值:
library(shiny)
library(shinyjqui)
server <- function(input, output) {
output$order <- renderPrint({ print(input$dest_order) })
output$ui_source <- renderUI({
orderInput('source', 'Source', items = month.abb,
connect = 'dest')
})
output$ui_dest <- renderUI({
orderInput('dest', 'Dest', items = NULL, placeholder = 'Drag items here...', connect = 'source')
})
observeEvent(input$btn,{
# Render the UI for the orderInput widgets again
output$ui_source <- renderUI({
orderInput('source', 'Source', items = month.abb,
connect = 'dest')
})
output$ui_dest <- renderUI({
orderInput('dest', 'Dest', items = NULL, placeholder = 'Drag items here...', connect = 'source')
})
})
}
ui <- fluidPage(
uiOutput("ui_source"),
uiOutput("ui_dest"),
verbatimTextOutput('order'),
actionButton("btn","reset")
)
shinyApp(ui, server)https://stackoverflow.com/questions/60209235
复制相似问题