小编Hix*_*xon的帖子

R 点的闪亮重新着色

我想要单击选择点并根据颜色对它们进行分组。

我可以将带有颜色信息的选定点保存到新的数据框中并绘制它,但是我想跟踪并查看交互式绘图上已选择的内容。

如何在“添加选择”后显示/标记已选择的点或使其永久化?

library(shiny)
library(tidyverse)
library(DT)
library(colourpicker)

ui = fluidPage(
    colourInput("col", "Select colour", "purple"),
    actionButton("addToDT", "Add selection", icon = icon("plus")), hr(),
    plotOutput("plot", click = "plot_click", dblclick = "plot_reset"),
    DT::dataTableOutput('plot_DT'), hr(),
    textOutput("clickcoord"),
    DT::dataTableOutput('final_DT'),
    plotOutput("plotSelected")
)

server = function(input, output, session) {
    
    selectedPoint = reactiveVal(rep(FALSE, nrow(mtcars)))
    
    output$clickcoord <- renderPrint({
        print(input$plot_click)
    })
    
    observeEvent(input$plot_click, {
        clicked = nearPoints(mtcars, input$plot_click, allRows = TRUE)$selected_
        selectedPoint(clicked | selectedPoint())
    })
    
    observeEvent(input$plot_reset, {
        selectedPoint(rep(FALSE, nrow(mtcars)))
    })
    
    output$plot_DT = DT::renderDataTable({
        mtcars$sel = selectedPoint()
        mtcars = dplyr::filter(mtcars, sel == TRUE) %>% …
Run Code Online (Sandbox Code Playgroud)

r event-handling ggplot2 shiny reactive

5
推荐指数
1
解决办法
264
查看次数

标签 统计

event-handling ×1

ggplot2 ×1

r ×1

reactive ×1

shiny ×1