[英]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.