【问题标题】:shiny: refresh plot to add new points闪亮:刷新绘图以添加新点
【发布时间】:2017-07-11 18:32:12
【问题描述】:

我有一个波浪图,我需要在其中识别曲线中的每个峰值:

我想做以下事情:

反应性地向图中添加点,我单击以标记每个峰的存在。

ui.R
plotOutput("plot1", click = "plot_click")

server.R
output$plot1 <- renderPlot({
  plot(x,y)
  points(x=input$plot_click$x,y=input$plot_click$y)
})

这里的问题是,虽然“plot_click”机制可以识别点的 x 和 y 位置,但“points()”命令只会导致点暂时出现然后消失。

我也尝试了 reactivePlot 但这返回了错误:

could not find function "func"

【问题讨论】:

    标签: shiny


    【解决方案1】:

    排序。基于上一篇文章的帮助:avoid double refresh of plot in shiny

    library(shiny)
    ui <- basicPage(
      actionButton("submit","submit"),
      plotOutput("plot1", click = "plot_click"),
      verbatimTextOutput("info"),
      tableOutput('table')
    )
    
    server <- function(input, output) {
      click_saved <- reactiveValues(singleclick = NULL)
      observeEvent(eventExpr = input$plot_click, handlerExpr = { click_saved$singleclick <- input$plot_click })
      rv=reactiveValues(m=data.frame(x=0,y=0))
      output$plot1 <- renderPlot({
        plot(x,y, type='l')
        points(rv$m$x[-1],rv$m$y[-1])
      })
    
      output$info <- renderText({
        paste0(unlist(click_saved$singleclick))
      })
    
    
      observeEvent(input$submit, {
        if (input$submit > 0) {
          rv$m <- rbind(rv$m,unlist(click_saved$singleclick))
        }
      })
    
      output$table <- renderTable({
        if (is.null(rv$m)) {return()}
        print(rv$m)
      }, 'include.rownames' = FALSE
      , 'include.colnames' = TRUE
      )
    
    }
    
    shinyApp(ui, server)
    

    【讨论】:

      猜你喜欢
      • 2021-04-30
      • 1970-01-01
      • 1970-01-01
      • 2017-03-07
      • 2020-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-30
      相关资源
      最近更新 更多