Search code examples
rshinyggplotly

Scatterplot that is created according to color, shape and fill is not displayed when using ggplotly()


Im trying to create a scatter plot that codes my data according to shape, colour and fill. While it is displayed with ggplot when I use plotly it is not displayed.

## app.R ##
library(shiny)
library(shinydashboard)
library(ggplot2)
library(plotly)
ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    plotOutput("plot")

  )
)

server <- function(input, output) {
  blank.test <- read.table(header=T, text="Colour Shape Fill X13C X15N
1       B     B    A   16   10
2       D     A    A   16   12
3       E     A    B   17   14
4       C     A    A   14   18
5       A     A    B   13   18
6       C     B    B   18   13
7       E     C    B   10   12
8       E     A    B   11   10
9       A     C    B   14   13
10      B     A    A   11   14
11      C     B    A   11   10
12      E     B    A   11   19
13      A     B    A   10   18
14      A     C    B   17   16
15      E     B    A   16   13
16      A     C    A   16   14") 

blank.test$inter <- with(blank.test, interaction(Shape,  Fill))
output$plot<-renderPlotly({
  p<-ggplot(blank.test, aes(x=X13C, y=X15N)) + 
    geom_point(aes(shape=inter,color=Colour)) + scale_shape_manual(name="shape", values=c(0,15,1, 16, 2, 17)) + scale_color_manual(name="colour", values=c("red","blue","yellow", "green", "purple"))
  ggplotly(p)
})
}

shinyApp(ui, server)

Solution

  • Just replace plotOutput by plotlyOutput