0

I produced a ggplot with a png as background. Local this workspace without a problem. But as a shiny the plot is not working.

Server.R

library(shiny)
library(shinydashboard)
library(shinyWidgets)
library(dashboardthemes)
library(DT)
library(png)
library(rasterImage)
library(ggpubr)
library(plotly)

# Define server logic required to draw a histogram
shinyServer(function(input, output, session) {

    output$ShootPosition <- renderPlotly({

        data <- data.frame(x = rnorm(100),
                           y = rnorm(100))
        ggplot(data, aes(x, y), tooltip = TRUE) +
               background_image(readPNG("test.png")) +
               geom_point()
      }) 

    }
)

ui.R

library(shiny)
library(shinydashboard)
library(shinyWidgets)
library(dashboardthemes)
library(DT)
library(png)
library(rasterImage)
library(ggpubr)
library(plotly)

header <- dashboardHeader(
    title = "Test"
)

sidebar <- dashboardSidebar(
    sidebarMenu(
        menuItem("Tables", icon = icon("table"), 
                 menuSubItem("Players", tabName = "Tables_Players")
        )
    )
)

body <- dashboardBody(
    tabItems(
        tabItem("Tables_Players",
                fluidPage(
                    titlePanel("Charts Players"),
                    fluidRow(
                        plotlyOutput("ShootPosition", height = '800px')
                    )
                )
        )
    )
)


ui = dashboardPage(
    header,
    sidebar,
    body)

The goal is to produce a shot map for ice hockey.

halfer
  • 19,824
  • 17
  • 99
  • 186
iPasc
  • 1
  • 1

1 Answers1

0

In the server section, you are not defining a ggplotly object for renderPlotly. Only a ggplot object will not render in renderPlotly. Please define p<-ggplot()+..., then define ggplotly(p) as the last statement within renderPlotly. That should work.

YBS
  • 19,324
  • 2
  • 9
  • 27