r - Highcharter R 对数轴自定义按钮

标签 r highcharts shiny r-highcharter

我想要用户可选择的 y 轴刻度对数/线性。我从答案here中得到了自定义按钮代码它可以显示自定义按钮,但我无法让按钮工作(即更改 y 轴)。我确信我看到它们工作了一两次,但不一致,现在它们根本不起作用,所以我怀疑语法中有一个我找不到的错误。它既不能在 RStudio 查看器中工作,也不能在 Shiny 的应用程序中工作。

library(highcharter)
library(shiny)

ui <- fluidPage(
  mainPanel(
    highchartOutput("plot_hc")
  )
)

server <- function(input, output) {
  output$plot_hc <- renderHighchart({

  dl <- data.frame(x = 1:10, y = 2 ^ (10:1))

  highchart() %>%
    hc_add_series(dl, type = 'line', hcaes(x, y)) %>%
    hc_exporting(
       enabled = TRUE
      ,buttons = list(
         customButton = list(text = 'Linear'
                            ,onclick = JS("function() {this.yAxis[0].update({type: 'linear'});}")
                            )
        ,customButton = list(text = 'Log'
                            ,onclick = JS("function() {this.yAxis[0].update({type: 'logarithmic'});}")
                            )
        )
      )
  })
}

shinyApp(ui, server)

最佳答案

不能有重复的键 (customButton)。做:

,buttons = list(
  customButton = list(text = 'Linear'
                      ,onclick = JS("function() {this.yAxis[0].update({type: 'linear'});}")
  )
  ,customButton2 = list(text = 'Log'
                       ,onclick = JS("function() {this.yAxis[0].update({type: 'logarithmic'});}")
  )

关于r - Highcharter R 对数轴自定义按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65808736/

相关文章:

r - 如何在 Shiny Leaflet map 中将图层置于顶部

使用 dplyr 删除所有变量均为 NA 的行

r - 在 ggplot2 中创建范围(走廊)图

javascript - 如何在鼠标悬停时展开/折叠 Shiny 的仪表板侧边栏?

r - 在 Shiny 中使用带有反应式数据集的 dplyr 输入变量时出现问题

javascript - 使用 highcharts 在堆栈标签中显示特定系列值

r - 如何从包含n * NA的数据框中删除行

r - 如何在r中保留带有特殊字符的单词

javascript - Highcharts (highstock) 在 x 轴折线图上绘制不正确的日期

highcharts - 有没有办法默认禁用图例项?