gpt4 book ai didi

Shiny :刷新情节以添加新点

转载 作者:行者123 更新时间:2023-12-04 19:51:09 26 4
gpt4 key购买 nike

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

我想做以下事情:

在我点击以标记每个峰的存在的位置 react 性地添加点。

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"

最佳答案

已排序。基于之前帖子的帮助: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)

关于 Shiny :刷新情节以添加新点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45042155/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com