2017-07-25 22 views
1

我使用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

似乎并不是'ggplot2'的平行坐标图是用刷子支持的。你可以看看'plotly'包而不是 –

+0

谢谢@Malvina_a。我看了一下Plotly,但是想用R/Shiny来达到这个目的。此外,请参阅:https://community.plot.ly/t/is-brushing-and-linking-available-for-the-python-api-in-plotly/2835 – FelipeRego

+0

有刷新和链接可用情节,看看这个链接:https://plot.ly/r/shiny-coupled-events/ –

回答

0

我试图找到解决您的问题,但实际上这是不可能的,在任何平行坐标图(既不plotlyggplot2brush检索数据。您可以在plotly中轻松使用画笔,但您无法从中获取数据(在您的情况下,它的格式为selectedData())。也许你应该尝试另一种情节类型。