I have a shiny dashboard in which I want to dynamically adapt both the graph and box height by using .js.
The issue is that this happens only when I pass height argument inside plotlyOutput()
and give it the input$GetScreenHeight
which contains the height. But I get object 'input' not found
. Can I pass just the plotlyOutput()
to the server inside?
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)
})
}
)