【问题标题】:How to delete a chart using observeEvent in shiny?如何在闪亮中使用observeEvent删除图表?
【发布时间】:2017-04-13 17:11:51
【问题描述】:

我在 flexdashboard 中使用闪亮的运行时。

我想在按钮按下时隐藏图表 (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")})


```

但是,当我单击按钮时,它不会隐藏 p1

【问题讨论】:

    标签: r shiny flexdashboard


    【解决方案1】:

    hide() 需要包含绘图的元素的id,但renderPlot 不允许在outputArgs 中设置outputId

    一种解决方法是使用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")})
    

    【讨论】:

    • 我收到此错误Warning: Error in observeEventHandler: could not find function "hide"
    • 我用一个可重现的例子重写了这个问题(对不起,我应该从一开始就这样做)。它似乎不起作用。
    • 只需将调用移出setup块中的useShinyjs
    猜你喜欢
    • 1970-01-01
    • 2018-08-17
    • 2019-03-24
    • 1970-01-01
    • 2019-06-07
    • 1970-01-01
    • 2016-10-11
    • 1970-01-01
    • 2022-11-29
    相关资源
    最近更新 更多