Loki Pushparaj
Loki Pushparaj

Reputation: 21

shiny arules htmlwidget graph only populates in Viewer

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)

Upvotes: 2

Views: 416

Answers (2)

Flavio Kaminishi
Flavio Kaminishi

Reputation: 63

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

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

Upvotes: 0

Michael Hahsler
Michael Hahsler

Reputation: 3075

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

Upvotes: 1

Related Questions