R Shiny: Vtree plot not rendering with Shiny

115 views Asked by At

How can I use vtree package in shiny? The desired plot is not appearing when trying to render it from serverside. My code:

library(shiny)
library(vtree)


# Define UI ----
ui <- pageWithSidebar(
  
  # App title ----
  headerPanel("Cyl vtree"),
  
  # Sidebar panel for inputs ----
  sidebarPanel(),
  
  # Main panel for displaying outputs ----
  mainPanel(
  plotOutput("plot1")
  
  )
)

# Define server logic to plot ----
server <- function(input, output) {
  output$plot1 <- renderPlot({
    vtree(mtcars, "cyl")
    })
}

shinyApp(ui, server)
1

There are 1 answers

0
Stéphane Laurent On BEST ANSWER

This is a HTML widget. You have to use the function renderVtree and vtreeOutput.

library(shiny)
library(vtree)


# Define UI ----
ui <- pageWithSidebar(
  
  # App title ----
  headerPanel("Cyl vtree"),
  
  # Sidebar panel for inputs ----
  sidebarPanel(),
  
  # Main panel for displaying outputs ----
  mainPanel(
    vtreeOutput("VTREE")
  )
)

# Define server logic to plot ----
server <- function(input, output) {
  output[["VTREE"]] <- renderVtree({
    vtree(mtcars, "cyl")
  })
}

shinyApp(ui, server)