我想改变我的指针在 R shiny 中的外观

问题描述 投票:0回答:0

我创建了一个带有仪表(转速计)的 R shiny 应用程序,指针看起来像:enter image description here

但我希望指针看起来像:enter image description here

这是我的代码

用新数据更新转速计图

  output$tachometer_plot <- renderPlotly({
    
    # Calculating the pointer coordinates
    pointer_angle <- 180 - ((tachometer_data[1] - 1) * 180 / 99)
    pointer_length <- 0.38 # Adjusting the pointer length
    pointer_x <- 0.5 + pointer_length * cos(pointer_angle * pi / 180)
    pointer_y <- 0.25 + pointer_length * sin(pointer_angle * pi / 180)
    
    custom_steps <- list(
      list(range = c(0, tachometer_data[2]), color = "#006F4E"),
      list(range = c(tachometer_data[2], tachometer_data[3]), color = "yellow"),
      list(range = c(tachometer_data[3], 100), color = "#991B56")
    )
    gauge_data <- data.frame(value = tachometer_data[1])
    plot_ly(gauge_data, type = "indicator", mode = "gauge", value = tachometer_data[1],
            gauge = list(axis = list(range = c(0, 100)), bar = list(thickness = 0.6, color = "transparent"),
                         bgcolor = "white", borderwidth = 2, bordercolor = "gray", steps = custom_steps,
                         dial = list(shape = "circle", bgcolor = "transparent"),
                         number = list(visible = FALSE))) %>%
      layout(margin = list(l = 20, r = 20), title = list(text = "Exposure to Carbon Intensive Industries", font = list(size = 14)),
             shapes = list(
               list(type = "path",
                    path = sprintf("M 0.5 0.5 L %f %f Z", pointer_x, pointer_y),
                    xref = "paper", yref = "paper",
                    fillcolor = "black", line = list(color = "black", width = 1))
             ),
             annotations = list(list(x = 0.5, y = 0.16, xref = "paper", yref = "paper",
                                     text = sprintf("%.1f", tachometer_data[1]),
                                     showarrow = FALSE, font = list(size = 30))))
r ggplot2 shiny plotly
© www.soinside.com 2019 - 2024. All rights reserved.