[英]How to delete a chart using observeEvent in shiny?
I am using the shiny runtime in flexdashboard.我在 flexdashboard 中使用了闪亮的运行时。
I would like to hide a chart on button press ( input$updt
), and I was trying this:我想在按下按钮时隐藏图表(
input$updt
),我正在尝试这个:
---
title: "Students Data - College of Business"
output:
flexdashboard::flex_dashboard:
orientation: columns
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(ggplot2)
library(shinyjs)
shinyjs::useShinyjs(rmd=TRUE)
```
Column {data-width=650}
-----------------------------------------------------------------------
### Chart A
```{r}
actionButton('updt', 'Update chart')
output$p1 <-renderPlot({ ggplot(diamonds, aes(carat, price)) + geom_point() }, height=800)
plotOutput("p1")
output$p2 <- renderPlot({
ggplot(mtcars, aes(cyl, disp))+ geom_point()
})
plotOutput("p2")
observeEvent(input$updt, {hide("p1")})
```
However, when I click on the button it doesn't hide p1
但是,当我单击按钮时,它不会隐藏
p1
hide()
needs the id
of the element that contains the plot, but renderPlot
doesn't allow setting the outputId
in outputArgs
. hide()
需要的id
包含的情节元素,但renderPlot
不允许设置outputId
在outputArgs
。
A workaround is to use plotOutput
:一种解决方法是使用
plotOutput
:
library(shinyjs)
shinyjs::useShinyjs(rmd=TRUE)
actionButton('updt', 'Update chart')
output$p1 <- renderPlot({load('p1.RDA') p1}, height=800)
plotOutput("p1")
output$p2 <- renderPlot(expr={ [...code to recalculate p2] })
plotOutput("p2")
observeEvent(input$updt, {hide("p1")})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.