【发布时间】:2019-11-13 08:10:56
【问题描述】:
我有一个闪亮的仪表板,我想在其中使用.js. 动态调整图形和框的高度问题是,只有当我在plotlyOutput() 中传递高度参数并给它input$GetScreenHeight 时才会发生这种情况包含高度。但我得到object 'input' not found。我可以只将plotlyOutput() 传递给里面的服务器吗?
jscode <-
'$(document).on("shiny:connected", function(e) {
var jsHeight = screen.height;
Shiny.onInputChange("GetScreenHeight",jsHeight);
});
'
shinyApp(
ui = dashboardPagePlus(
header = dashboardHeaderPlus(
),
sidebar = dashboardSidebar(),
body = dashboardBody(
tags$script(jscode),
boxPlus(
title = "Closable Box with dropdown",
closable = TRUE,
width = NULL,
status = "warning",
solidHeader = FALSE,
collapsible = TRUE,
plotlyOutput("pl",height = input$GetScreenHeight)
)
)
),
server = function(input, output) {
output$pl <- renderPlotly({
x <- faithful[, 2]
dat <- data.frame(xx = c(runif(100,20,50),runif(100,40,80),runif(100,0,30)),yy = rep(letters[1:3],each = 100))
p <- ggplot(dat,aes(x=xx)) +
geom_histogram(data=subset(dat,yy == 'a'),fill = "red", alpha = 0.2)
p <- ggplotly(p)
})
}
)
【问题讨论】:
-
为了完整起见:
renderUI是如果您想将plotlyOutput()移动到服务器端的方法,就像 here 所做的那样。
标签: r ggplot2 shiny plotly ggplotly