我正在使用Rstudio在R中创建一个flexdashboard / Shiny应用程序,并尝试使用两个组件创建一个仪表板:顶部的平行坐标图和图表下方的表格。
我尝试使用画笔和链接选择平行坐标图中的特定轴来影响和过滤表格中的数据。
以下是我的代码(改编自https://jjallaire.shinyapps.io/shiny-ggplot2-brushing/):
---
title: "ggplot2 Brushing"
output:
flexdashboard::flex_dashboard:
orientation: columns
social: menu
source_code: embed
runtime: shiny
---
```{r global, include=FALSE}
# load data in 'global' chunk so it can be shared by all users of the dashboard
library(datasets)
mtcars2 <- mtcars[, c("mpg", "cyl", "wt")]
```
```{r}
# Reactive that returns the whole dataset if there is no brush
selectedData <- reactive({
data <- brushedPoints(mtcars2, input$plot1_brush)
if (nrow(data) == 0)
data <- mtcars2
data
})
```
Column {data-width=650}
-----------------------------------------------------------------------
### Miles Per Gallon vs. Weight {data-width=600}
```{r}
library(ggplot2)
library(GGally)
plotOutput("plot1", brush = brushOpts(id = "plot1_brush"))
output$plot1 <- renderPlot({
ggparcoord(mtcars2) + geom_line()
})
```
### Car Details {data-width=400}
```{r}
renderTable({
selectedData()
}, rownames = TRUE)
```
如您所见,刷牙和链接无法正常工作。我在这里错过了什么?我已经阅读了一些关于这个主题的问题,尤其是关于XY变量的问题,并且仅适用于散点图等。但当然有一种解决方法,我似乎无法找到解决方案。有没有人知道如何在Shiny中使用平行坐标进行刷洗和链接工作?
答案 0 :(得分:0)
我试图找到您问题的解决方案,但实际上目前无法使用brush
从任何平行坐标图(plotly
或ggplot2
)检索数据。您可以在plotly
中轻松使用画笔,但您无法从中获取数据(在您的情况下,它是selectedData()
)。也许你应该尝试另一种情节类型。