【问题标题】:Identifying the points and printing a datatable with brushedPoints识别点并使用brushedPoints 打印数据表
【发布时间】:2018-06-26 13:37:50
【问题描述】:

我想对这个链接Identify points within a rectangle in a scatterplot已经解决的问题使用主成分分析。图表显示正确,但我在显示表格时错过了一些东西。如果有人知道问题出在哪里,请帮忙。

代码(编辑):

head(decathlon2.active[, 1:6], 4)
##         X100m Long.jump Shot.put High.jump X400m X110m.hurdle
## SEBRLE   11.0      7.58     14.8      2.07  49.8         14.7
## CLAY     10.8      7.40     14.3      1.86  49.4         14.1
## BERNARD  11.0      7.23     14.2      1.92  48.9         15.0
## YURKOV   11.3      7.09     15.2      2.10  50.4         15.3

#################################################################

library(shiny)
library(DT)

server <- function(input, output) {
  output$plot1 <- renderPlot({
    data(decathlon2)
    decathlon2.active <- decathlon2[1:23, 1:10]
    head(decathlon2.active[, 1:6], 4)
    res.pca <- PCA(decathlon2.active, graph = FALSE)
    fviz_pca_ind(res.pca)

  })

  df <- reactive({
    res.pca$ind$coord
  })

    output$plotui <- renderUI({
    plotOutput("plot1", height=300,
               brush = brushOpts(id = "plot_brush")
    )
  })

  output$plot_brushed_points <- renderDataTable({
      res <- brushedPoints(df(), input$plot_brush) 

    datatable(res)
  })
}

ui <- fluidPage(
  uiOutput("plotui"),
  dataTableOutput("plot_brushed_points")
)

shinyApp(ui = ui, server = server)

结果:

【问题讨论】:

  • 很遗憾,如果没有 decathlon2 数据,将无法重现。

标签: r datatable shiny pca brush


【解决方案1】:

我认为您的问题是在res &lt;- brushedPoints(df, input$plot_brush) 中您引用了数据框df,其中包含您在renderPlot({...}) 命令中生成的数据。该数据将无法在您的表输出命令中调用。尝试添加

df <- reactive({
    #your data here
})

然后调用res &lt;- brushedPoints(df(), input$plot_brush)

如果这似乎不起作用,请发布一些示例数据,我会更新我的答案。

编辑:

这里有一个更明确的建议。您仍在尝试从renderPlot({...}) 调用数据。尝试在响应式语句中生成数据,然后在之后调用它。

df <- reactive({
    data(decathlon2)
    decathlon2.active <- decathlon2[1:23, 1:10]
    res.pca <- PCA(decathlon2.active, graph = FALSE)
})

您仍然需要为brushedPoints 提供xvar 和yvar 参数。

https://shiny.rstudio.com/reference/shiny/latest/brushedPoints.html

【讨论】:

  • 我更正了您的版本,但问题仍然存在
  • 你能帮帮我吗,这对我来说很重要。
  • 我不熟悉你的数据或你的绘图方法,这就是我所拥有的。
  • 我按照你的要求改了,还是一样的错误,我给了上面的数据集
  • 可以使用mtcars数据库
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多