![](/img/trans.png)
[英]Display download button in Shiny R only when output appears in Main Panel
[英]Clear the main Panel to display the other reactive output in shiny r studio
我的主面板中有一個 dataTableOutput。 然后我有一個動作按鈕“Go”。 單擊“開始”后,我希望 rHandsOutput 出現在主面板中,但不在 dataTableOutput 下方。 如何刪除主面板中的 dataTableOutput 並顯示 rHandsOutput。 在我當前的代碼中,兩個表一起出現。 單擊“Go”后,第二個表位於第一個表下,我只想顯示第二個表 (rHandsOutput),從主面板中刪除第一個表。
請幫幫我!1
您可以結合使用insertUI
和removeUI
來使 UI 組件動態化。 例如:
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
actionButton(inputId = "go", label = "Go")
),
mainPanel(
fluidRow(
tags$div(id = "firstOutput",
dataTableOutput("myDataTable"))
),
fluidRow(
tags$div(id = "placeholder") # the dynamic UI will be inserted relative to this placeholder
)
))
)
server <- function(input, output) {
output$myDataTable <- renderDataTable(iris)
observeEvent(input$go, {
removeUI("div:has(>#firstOutput)")
insertUI(
selector = "#placeholder",
where = "afterEnd", # inserts UI after the end of the placeholder element
ui = fluidRow(
actionButton(inputId = "newButton", label = "A new button")))
})
}
shinyApp(ui = ui, server = server)
您可以使用showElement()
和hideElement()
從shinyjs
:
observeEvent(input$go, {
shinyjs::hideElement(“firsttable”)
shinyjs::showElement(“rHandsOutput”)
})
假設第一個表的ID是“firsttable”,第二個表的ID是“rHandsOutput”,“Go”按鈕的ID是“go”。
動態生成 ui。
使用uiOutput("someidentifier")
在ui.r
,然后用你的數據表在以下填充server.r
output$someidentifier <-
renderUI({
dataTableOutput("datatableidentifier")
})
output$datatableidentifier <- renderDataTable(iris)
uiOutput
代替您想要動態添加的任何 ui 元素(在ui.r
)。 該 ui 的必要代碼然后移動到server.r
renderUI
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.