我希望能夠移除一個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)