Graphical integration with shinydashboard

I used brilliant for several small projects, and now I'm trying to make a shinydashboard package that looks pretty promising. I also want to integrate the interactive plot using plotly (although other libraries may be considered in the future).

I have no problems with running examples that integrate the plot into brilliant ( example ), but I encounter problems when trying to achieve similar results using shinydashboard.

For example, the code below (app.R) does not work correctly.

library(shiny)
library(shinydashboard)
library(plotly)
library(ggplot2)




data(movies, package = "ggplot2")
minx <- min(movies$rating)
maxx <- max(movies$rating)


#######
####### UI
#######

ui <- dashboardPage(

  ############# Header
  dashboardHeader(title = "Test"),

  ############# Sidebar
  dashboardSidebar(
    sidebarMenu(
      menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard"))
    )
  ),


  ############# Dashboard body
  dashboardBody(
    # Boxes need to be put in a row (or column)
    fluidRow(
      box(plotOutput("plot1"), width=6, height=500),
      box(plotOutput("plot2"), width=6, height=500)
    )
  )
)


#######
####### Server
#######


server <- function(input, output, session) {



  output$plot1 <- renderPlot({


    # a simple histogram of movie ratings
    p <- plot_ly(movies, x = rating, autobinx = F, type = "histogram",
                 xbins = list(start = minx, end = maxx, size = 2))
    # style the xaxis
    layout(p, xaxis = list(title = "Ratings", range = c(minx, maxx), autorange = F,
                           autotick = F, tick0 = minx, dtick = 2))

  })

  output$plot2 <- renderPlot({


    hist(movies$rating, col="blue")

  })
}


shinyApp(ui, server)

, : , R. , Rstudio. runApp(), - , - .

( , ), , , /. , , , ( ), , , .

, ( , ). ?

+4
1

, , ui

  box(plotOutput("plot1"), width=6, height=500)

  box(plotlyOutput("plot1"), width=6, height=500)

server

output$plot1 <- renderPlot({
......

output$plot1 <- renderPlotly({
....
+8

Source: https://habr.com/ru/post/1617630/


All Articles