我想要用户可选择的 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/