2

I'm trying to create a shiny app for visualizing association rules. Its running fine except the graph plot keeps getting populated in the R Studio Viewer instead of within the Shiny App. Please Help!. Code below (am running R v 3.4.2)

ui<-fluidPage(
titlePanel("test"),
sidebarLayout(
sidebarPanel(
radioButtons("hier", "Hierarchy:", c("DEPT", "SUB_DEPT", "CLASS")),      
selectInput("period",label = em("Period"), c("P1","P2"),selected = 'P1'),      
sliderInput("n_rules", "No. of rules:",min = 0, max = 100, value = 10, 
step = 10)
),
mainPanel(plotlyOutput("network_graph"))
)
)
server <- function(input, output){
output$network_graph <- renderPlotly({    
if (input$hier == 'DEPT' & input$period == 'P1') {
print(
(
plot(head(sort(DEPT_P1_All_Customers),input$n_rules), engine = 
"htmlwidget", method = "graph", height = "800px")
))
}
})
}
shinyApp(ui, server)
  • I do not use Ploty but it the docs it uses `plot_ly` instead of `plot`, maybe that will help? Also I am not understanding why you are using the `print` function inside your `renderPlotly`. – Chabo Dec 12 '18 at 21:56
  • tried 2 changes: 1. Removed the print function 2. Used plotOutput and renderPlot instead. Both giving me same results. The graph is populated in the Viewer instead of within the Shiny app. plot_ly needs a dataframe - it doesn't recognize the arules data – Loki Pushparaj Dec 13 '18 at 04:09
  • 1
    The problem seems to be because of the engine="htmlwidget". if I use engine = "default", the plot is rendering correctly within the Shiny app.. But the htmlwidget plot is so much better and interactive which i want to use. – Loki Pushparaj Dec 13 '18 at 04:58

2 Answers2

1

The method "graph" returns a htmlwidget from visNetwork, so you need to use renderVisNetwork() instead of renderPlotly() in shiny.

Michael Hahsler
  • 2,965
  • 1
  • 12
  • 16
0

For "graph" method change your input and output, as:

plotlyOutput("network_graph") to visNetworkOutput("network_graph") and renderPlotly to renderVisNetwork.