How to use graphs built by the ggplot function on a Shiny DASHBOARD

Asked

Viewed 22 times

0

I have some graphics ready generated by the ggplot package and am trying to build a Rdashboard Shiny and take advantage of these visual products. However, it is being much more complicated than I imagined, I keep getting a lot of errors, as I should refer my ggplot objects ready on the back.end of Shiny Dash board?

I’ll put a piece of the Dash script to better illustrate the situation.

"scriptsimp" is an object that refers to the name of the script file that generates the graphics by ggplot "SS_GRAPH" is the name of a graphical object created by ggplot

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

source(scriptsimp)


ui <- dashboardPage(
  
  dashboardHeader(title = 'SIM-P'),
  dashboardSidebar(
    menuItem("Geral", tabName = "Geral"),
    menuItem("2020", tabName = "2020"),
    menuItem("2021", tabName = "2021")
  ),
  dashboardBody(tabItem(
    tabName = 'Geral', 
      fluidRow(plotOutput("ss"))
  )
    
  )
   
  )


source(scriptsimp)
server <- function(input, output) {
  output$ss <-renderPlotly({SS_GRAPH)}
  • Unfortunately, this question cannot be reproduced by anyone trying to answer it. Please take a look at this link (mainly in the use of function dput) and see how to ask a reproducible question in R. So, people who wish to help you will be able to do this in the best possible way.

1 answer

0

I didn’t understand exactly what you need, but I noticed a detail that can help you. You need to set renderPlot to render your chart.

output$meu_grafico <- renderPlot({
     ggplot(
      my_df,
      aes(y = y, x = x, fill = dados)
    ) +
      geom_col()

Still in the ui part, you put where the graph is. Example:

fluidRow(
      plotOutput("meu_grafico")
    )

Browser other questions tagged

You are not signed in. Login or sign up in order to post.