I would like to have the shiny-plotly output height and width adjusted to the current window size. I have tried to use the below but of no use based on this post but it throws an error: Error in UseMethod: no applicable method for 'plotly_build' applied to an object of class "shiny.tag"
. I do exactly the same but I use shinydashboard instead.
library(shiny)
library(shinydashboard)
library(plotly)
shinyApp(
ui = dashboardPagePlus(
header = dashboardHeaderPlus(
enable_rightsidebar = TRUE,
rightSidebarIcon = "gears"
),
sidebar = dashboardSidebar(),
body = dashboardBody(
tags$head(tags$script('
var dimension = [0, 0];
$(document).on("shiny:connected", function(e) {
dimension[0] = window.innerWidth;
dimension[1] = window.innerHeight;
Shiny.onInputChange("dimension", dimension);
});
$(window).resize(function(e) {
dimension[0] = window.innerWidth;
dimension[1] = window.innerHeight;
Shiny.onInputChange("dimension", dimension);
});
')),
navbarPage("Navbar!",
tabPanel("Plot",
boxPlus(
plotlyOutput("plot1")
)
),
tabPanel("Summary"
))
),
title = "Right Sidebar"
),
server = function(input, output) {
output$plot1 <- renderPlotly({
p<-plot(cars, type=input$plotType)
ggplotly(p, width = (0.95*as.numeric(input$dimension[1])), height = as.numeric(input$dimension[2]))
})
}
)