我想把这个图例放在我闪亮的流体页边栏中的一个图表上。我有两个想法:1)通过ggplotly获取图例grob并放入侧边栏或2)渲染具有相同颜色的图例,侧边栏中没有绘图。不幸的是,我不确定如何做到这些。有任何想法吗?示例闪亮如下。
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")
)
) # End fluid page
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
)
})
} # End server function
shinyApp(ui = ui, server = server)