Hi, it works for me, please check this script. Hope helps
library(shiny)
library(shinydashboard)
library(plotly)
library(ggplot2)
library(dplyr)
header<- shinydashboardPlus::dashboardHeader(
title = "Two Plots in one page",
titleWidth = '500px'
)
sidebar <- dashboardSidebar(
sidebarMenu(id = "tabs"
) #sidebar menu
)
body <-dashboardBody(
tabsetPanel(
tabPanel(title = "Summary Page-1",
fluidRow(
column(width = 6,plotlyOutput("plot1",height = 400,width = '100%')),
column(width = 6,plotlyOutput("plot10",height = 400,width = '100%')))
),
tabPanel(title = "Summary Page-2",
fluidRow(
column(width = 6,plotOutput("plot2",height = 400,width = '100%')),
column(width = 6,plotOutput("plot20",height = 400,width = '100%')))
)
)
)
ui <- dashboardPage(
header = header,
sidebar = sidebar,
body = body
)
server <- function(input, output, session) {
output$plot1 <- renderPlotly({
fig <- plot_ly(mtcars, y = ~mpg, color = ~factor(cyl), type = "box")
fig
})
output$plot10 <- renderPlotly({
fig <- plot_ly(mtcars, y = ~mpg, color = ~factor(cyl), type = "bar")
fig
})
output$plot2 <- renderPlot({
hist(iris$Sepal.Length,
main = NULL,
labels = TRUE,
col = "#87CEFA",
border = "white",
breaks = 10)+geom_point()+geom_smooth()+coord_cartesian()%>%
abline(v = mean(iris$Sepal.Length, na.rm = T),
col = "red",
lwd = 2)%>%
abline(v = median(iris$Sepal.Length, na.rm = T),
col = "black",
lwd = 2)
})
output$plot20 <- renderPlot({
boxplot(x = iris$Sepal.Length,
main = NULL,
labels = TRUE,
# col = "#87CEFA",
# border = "black",
col = "orange",
border = "brown",
notch = TRUE)
})
}
shinyApp(ui, server)