Home > database >  Is there a way to render plots from Data Explorer library on Shiny App
Is there a way to render plots from Data Explorer library on Shiny App

Time:11-17

I'm trying to plot the outcomes of EDA on to Shiny App, I have been using DataExplorer library for the same and i'm able to perform operations on rmarkdown notebook. I was thinking to integrate the plots to shiny app using the below code but i'm running into errors,Can you please assist me in this regard and also suggest me if there is a way possible to achieve this.

UI part 

library(shiny)
library(DataExplorer)

  fluidRow(width=12,
           column(12,plotOutput("struct"))
    
  )

Server block
df<-read.csv("/path/to/csv/file.csv")
            output$struct<-renderPlot({
              req(df)
              
              plot_str(df)
            })

Thanks for the help in advance

CodePudding user response:

DataExplorer::plot_str by default prints a networkD3::diagonalNetwork, however, it returns a list.

If you want to render the diagonalNetwork object in shiny you'll need to use networkD3::renderDiagonalNetwork. Please check the following:

library(shiny)
library(DataExplorer)
library(datasets)
library(networkD3)

# DF <- read.csv("/path/to/csv/file.csv")
DF <- mtcars

ui <- fluidPage(
  fluidRow(column(12, diagonalNetworkOutput("struct")))
)

server <- function(input, output, session) {
  output$struct <- renderDiagonalNetwork({
    req(DF)
    diagonalNetwork(plot_str(DF, print_network = FALSE))
  })
}

shinyApp(ui, server)
  • Related