bslib
在他们的expandable sparklines周围有有用的文档.文档使用javascript修改卡片展开时现有的plotly plot.我试着模仿同样的行为,但要用highcharter情节代替情节.
我希望这是在javascript,而不是使用shiny::getCurrentOutputInfo()
,因为它创建了一个lag时,扩大和最小化窗口.
我希望图中的x和y轴都可见,以及图是可导出时展开和隐藏这些元素时最小化.这基本上是我希望看到的使用getCurrentOutputInfo
函数的行为(注意延迟和情节的重新渲染).
Example App
library(shiny)
library(bslib)
library(highcharter)
ui <- page_fluid(
value_box(
title = "Test",
value = "Test",
showcase = highchartOutput("hcp"),
showcase_layout = showcase_top_right(),
full_screen = TRUE,
theme = "success"
)
)
server <- function(input, output) {
df <- data.frame(dose=c("D0.5", "D1", "D2"),
len=c(4.2, 10, 29.5))
output$hcp <- renderHighchart({
highchart_scatter()
})
highchart_scatter <- function(x) {
info <- getCurrentOutputInfo()
large <- isTRUE(info$height() > 200)
df2 <- df %>%
hchart('line', hcaes(x = dose, y = len))
if(large){
df2 <- df2 %>%
hc_exporting(enabled = TRUE)
} else {
df2 <- df2 %>%
hc_xAxis(visible = FALSE) %>%
hc_yAxis(visible = FALSE)
}
return(df2)
}
}
shinyApp(ui, server)
这是一个js示例代码,用于重构一个plotly图,我基本上想模仿它.
plotly javascript example
htmlwidgets::onRender(
"function(el) {
var ro = new ResizeObserver(function() {
var visible = el.offsetHeight > 200;
Plotly.relayout(el, {'xaxis.visible': visible});
});
ro.observe(el);
}"
)