4

I have a shiny app with server.R and ui.R.

This is the code in server.R:

library(shiny)
library(ggplot2)
library(plotly)

server <- shinyServer(function(input, output, session) {

dat=data.frame(mycolA=c(1,2,3,4), mycolB=c(12,13,16,10), mycolC=c(330,510,290,530))

    p=ggplot(dat,aes(x=mycolB, y=mycolC)) +
    geom_path(aes(colour=mycolA)) # <----------------------------------
    #geom_path() 

    output$myggplotwithplotly=renderPlotly({
    p
    })

    output$myggplotonly=renderPlot({
        p
    })

})

This is the code in ui.R:

library(shiny)
library(ggplot2)
library(plotly)

ui <- shinyUI(fillPage(
fillRow(
plotlyOutput("myggplotwithplotly", height="100%"), plotOutput("myggplotonly", height="100%")
  )

))

It returns:

Why is there no line in the left diagram?

As you see, there is no line in the plotly-diagram on the left.

If I use geom_path() instead of geom_path(aes(colour=mycolA)) in server.R then I get:

enter image description here

My Question: Why is the coloured line not displayed in plotly and how do I need to change the code to display it?

nexonvantec
  • 572
  • 1
  • 5
  • 18
  • 2
    Unfortunately, it might not be possible yet. When you trying to convert your `ggplot` code to `plot_ly` using: `plot_ly(dat, x = ~mycolB, y = ~mycolC, color = ~mycolA, type = "scatter", mode = "lines")`, I get the warning: "Numeric color variables cannot (yet) be mapped to lines. when the trace type is 'scatter' or 'scattergl'." – Mike H. Jun 26 '18 at 16:11
  • 1
    I suggest opening a request on github. – M-- Jun 26 '18 at 17:08
  • @masoud done that. – nexonvantec Jun 27 '18 at 07:27
  • x-ref: https://github.com/ropensci/plotly/issues/1294 – mschilli Jun 27 '18 at 07:53

0 Answers0