用于对数轴的 Highcharter R 自定义按钮
Highcharter R custom button for log axis
我想要用户可选择的 y 轴刻度 log/linear。我从答案 中获得了自定义按钮代码,它可以显示自定义按钮,但我无法让按钮工作(即更改 y 轴)。我确定我看到它们工作过一两次,但不是始终如一,现在它们根本不起作用,所以我怀疑语法中存在我找不到的错误。它既不能在 RStudio 查看器中工作,也不能在闪亮的应用程序中工作。
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'});}")
)
我想要用户可选择的 y 轴刻度 log/linear。我从答案
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'});}")
)