R 根据2个输入,使用操作按钮进行绘图

R 根据2个输入,使用操作按钮进行绘图,r,shiny,ggplotly,R,Shiny,Ggplotly,我正在尝试制作具有以下特征的产品: 它在开始时不显示任何内容(无打印输出),并且 它仅在单击按钮后更新(而不是在更改第一个或第二个变量时) 到目前为止,我已经使用了observeEvent和eventReactive,但它们都还没有起作用。对于这个问题,我以iris为例。在过去的几个小时里,我一直在绞尽脑汁,我使用了许多不同的技术,如观察事件、事件反应、隔离()等等 代码: 库(闪亮) 图书馆(数据集) 图书馆(GG2) 数据(iris) uireq(输入$gobutton)应该可以做到这一

我正在尝试制作具有以下特征的产品:

  • 它在开始时不显示任何内容(无打印输出),并且
  • 它仅在单击按钮后更新(而不是在更改第一个或第二个变量时)
到目前为止,我已经使用了observeEvent和eventReactive,但它们都还没有起作用。对于这个问题,我以iris为例。在过去的几个小时里,我一直在绞尽脑汁,我使用了许多不同的技术,如观察事件、事件反应、隔离()等等

代码:

库(闪亮)
图书馆(数据集)
图书馆(GG2)
数据(iris)
uireq(输入$gobutton)应该可以做到这一点

output$plot <- renderPlotly({
    req(input$gobutton)

    iris_plot <- ggplot(iris, aes_string(x=input$var1,
                                         y=input$var2,
                                         colour="Species")) + geom_point()

    ggplotly(iris_plot)
output$plot这应该有效

rv <- reactiveValues(var1=NULL,var2=NULL)
observeEvent(input$gobutton,{
   rv$var1 <- input$var1
   rv$var2 <- input$var2
})
output$plot <- renderPlotly({
    if (!is.null(rv$var1) & !is.null(rv$var2)){
                iris_plot <- ggplot(iris, aes_string(x=rv$var1, 
                                                     y=rv$var2,
                                                     colour="Species")) + geom_point()
                ggplotly(iris_plot)
    }
})



rv感谢您的回复。但是在第一次按下按钮(有效)后,它会立即更新,而无需再次按下按钮?非常感谢!
rv <- reactiveValues(var1=NULL,var2=NULL)
observeEvent(input$gobutton,{
   rv$var1 <- input$var1
   rv$var2 <- input$var2
})
output$plot <- renderPlotly({
    if (!is.null(rv$var1) & !is.null(rv$var2)){
                iris_plot <- ggplot(iris, aes_string(x=rv$var1, 
                                                     y=rv$var2,
                                                     colour="Species")) + geom_point()
                ggplotly(iris_plot)
    }
})