我有一个闪亮的仪表板,我想在其中使用.js.
动态调整图形和框的高度,问题是,只有当我在plotlyOutput()
内传递height参数并将其赋予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),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)
})
}
)