【发布时间】:2021-08-06 17:29:09
【问题描述】:
我正在编写一个闪亮的应用程序。
在下面的示例中,我想:
- 当我按下“按钮”时隐藏“plot1”。我尝试使用 shinyjs::hide() 没有成功
- 能够在 HTML 页面的同一位置显示“plot1”或“plot2”图形。目前,这是不合适的,因为“plot1”和页面底部的标题h3之间有很大的空间。
我想要的是当没有生成“plot2”时,只有“plot1”和没有空格的标题h3。而当“plot2”创建后,“plot1”不再显示,“plot2”与网页上的“plot1”完全相同 希望足够清楚。
library(shiny)
library(shinyjs)
# Global variables can go here
n <- 200
# Define the UI
ui <- bootstrapPage(
numericInput('n', 'Number of obs', n),
actionButton("button", "Validate second plot"),
plotOutput('plot1'),
plotOutput('plot2'),
h3("Dashboard end...")
)
# Define the server code
server <- function(input, output) {
output$plot1 <- renderPlot({
hist(runif(isolate(input$n)),main="First histogram")
})
observeEvent(input$button, {
shinyjs::hide("plot1")
output$plot2 <- renderPlot({
hist(runif(isolate(input$n)),main="Second histogram")
})
})
}
# Return a Shiny app object
shinyApp(ui = ui, server = server)
【问题讨论】: