I would like to put a legend on one of my graphs on the sidebar of my shiny fluid page. I had two ideas for this: 1) Get the legendary coffin through ggplotly and place the sidebar, or 2) visualize the legend with the same colors and no plot on the sidebar. Unfortunately, I do not know how to do this. Any ideas? An example shines below.
library(plotly, shiny)
data <- ChickWeight
ag_data <- aggregate(data$weight,
list(time = data$Time, diet = data$Diet),
mean)
ui <- fluidPage(
sidebarPanel("Put Legend Here"),
mainPanel(
plotlyOutput("chick_weight")
)
)
server <- function(input, output) {
output$chick_weight <- renderPlotly({
plot_ly(
x = c(ag_data$time),
y = c(ag_data$x),
type = "scatter",
mode = "lines",
split = c(ag_data$diet),
showlegend = FALSE
)
})
}
shinyApp(ui = ui, server = server)

source
share