相关疑难解决方法(0)

带有nearPoints()的动态ggplot图层

我熟悉闪亮的基础知识但在这里挣扎.我希望能够在点击一个点时添加ggplot图层以突出显示该点.我知道这是可能的ggvis和画廊中有一个很好的例子,但我希望能够nearPoints()用来捕获点击作为ui输入.

我尝试了一些东西(见下文),它与ggplot图层分开显示然后消失.我已尝试过各种编辑reactive(),eventReactive()依此类推.

任何帮助深表感谢...

library(shiny)
library(ggplot2)

shinyApp(
  ui = shinyUI(
        plotOutput("plot", click = "clicked")
    ),

  server = shinyServer(function(input, output) {
    output$plot <- renderPlot({
      ggplot(mtcars, aes(x = mpg, y = wt)) +
        geom_point() +
        geom_point(data = nearPoints(mtcars, input$clicked), colour = "red", size = 5)
    })
  })
)
Run Code Online (Sandbox Code Playgroud)

我想我从概念上理解为什么这不起作用.该图具有依赖性,input$clicked这意味着当input$clicked更改时,图重新渲染,但这又会重置input$clicked.有点抓人22的情况.

r reactive-programming ggplot2 shiny

11
推荐指数
1
解决办法
1283
查看次数

Shiny:如何更改点击点的形状和/或大小?

我想更改下图中单击点的形状和大小。如何实现?对于这个玩具图,我将点数从原来的 100k 减少到 2k。因此,预期的解决方案应该是高度可扩展的,并且不偏离原始图,即点击点更新之前和之后的所有颜色应该相同。

library(shiny)
library(plotly)

df <- data.frame(X=runif(2000,0,2), Y=runif(2000,0,20), 
                 Type=c(rep(c('Type1','Type2'),600),
                        rep(c('Type3','Type4'),400)),
                 Val=sample(LETTERS,2000,replace=TRUE))

# table(df$Type, df$Val)

ui <- fluidPage(
  title = 'Select experiment',
  sidebarLayout(
    sidebarPanel(
      checkboxGroupInput("SelType", "Select Types to plot:",
                  choices = unique(df$Type),
                  selected = NA)
    ),
    mainPanel(
      plotlyOutput("plot", width = "400px"),
      verbatimTextOutput("click")
    )
  )
)
Run Code Online (Sandbox Code Playgroud)
server <- function(input, output, session) {

  output$plot <- renderPlotly({
    if(length(input$SelType) != 0){
      df <- subset(df, Type %in% input$SelType)
      p <- ggplot(df, aes(X, Y, col = as.factor(Val))) + 
        geom_point()
    }else{
      p <- ggplot(df, aes(X, Y, …
Run Code Online (Sandbox Code Playgroud)

r shiny plotly ggplotly

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

标签 统计

r ×2

shiny ×2

ggplot2 ×1

ggplotly ×1

plotly ×1

reactive-programming ×1