首页 > 解决方案 > 悬停时使用透明模式栏背景进行绘图

问题描述

基于这个问题,我还想在将鼠标悬停在模式栏上时更改其背景颜色。我查看了 css,但找不到或更改相关部分。

这是一个要测试的小shinyApp:

library(shiny)
library(plotly)

ui <- fluidPage(
  plotlyOutput("plotly")
)

server <- function(input, output, session) {
  output$plotly <- renderPlotly({
    plot_ly(data = mtcars) %>% 
      add_markers(x=~mpg, y=~disp) %>% 
      layout(plot_bgcolor='transparent', paper_bgcolor='transparent')
  })
}

shinyApp(ui, server)

标签: rplotly

解决方案


我让它透明,但选项也是不可见的,所以我添加了颜色和活动颜色,请参见此处。如有必要,请随意更改。

library(shiny)
library(plotly)

ui <- fluidPage(
    plotlyOutput("plotly")
)

server <- function(input, output, session) {
    output$plotly <- renderPlotly({
        plot_ly(data = mtcars) %>% 
            add_markers(x=~mpg, y=~disp) %>% 
            layout(plot_bgcolor='transparent', paper_bgcolor='transparent', 
                   modebar=list(bgcolor='transparent', color='blue', activecolor='green'))
    })
}

shinyApp(ui, server)

推荐阅读