我希望能够移除一个UI元素,它是一个包含在fluidRow中的textInput,并将该元素(fluidRow和textInput)重新插入到UI中。但是,到目前为止,我没有取得任何成功。R将InsertUI插入FluidRow
removeUI按钮删除所有流体行,包括找到按钮的流体行。如果我尝试把它们放在一个单独的HTML部门中,它似乎没什么区别。或者如果它工作,textInput不再位于偏移量的流体行中。这是我的第一个闪亮的问题,所以请温柔我可能已经犯了一些明显的错误。
# Define UI
ui <- fluidPage(
fluidRow(column(2,actionButton("rmv", "Remove UI"))),
fluidRow(column(2,actionButton("add", "Add UI"))),
tags$div(id='aTextBox', fluidRow(column(2,offset=6,
textInput("txt", "This is no longer useful"))
)
)
)
# Server logic
server <- function(input, output) {
observeEvent(input$rmv, {
removeUI(
selector = "div:has(> #aTextBox)"
)
})
observeEvent(input$add, {
insertUI(
selector = "#add",
where = "afterEnd",
ui = tags$div(id='aTextBox', fluidRow(column(2,offset=6,
textInput("txt", "This is no longer useful"))
)
)
)
})
}
# Complete app with UI and server components
shinyApp(ui, server)