2017-07-25 47 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())。也許你應該嘗試另一種情節類型。