0

I have a plot that I show in a box and I want to modify the size of the box, but the plot is bigger than the box.How can I modify both of them, so that the plot remains and fits the box?

#in ui.r
 box(
                  title = "Veniturile si cheltuielile",
                  status = "primary",
                  solidHeader = TRUE,
                  collapsible = TRUE,
                  plotOutput("ven_vs_chelt")
                )




#in server.r
 output$ven_vs_chelt <- renderPlot({
    ggplot(ven_ch, aes(x=ven_ch$ani_tot, y=ven_chelt, fill=tip)) +
      geom_bar(stat="identity", position=position_dodge(), colour="black") +
      xlab("An") + ylab("Valoare venituri si cheltuieli(lei)") +
      scale_fill_manual(values=c("#F78181", "#81F79F"))
  })
mpalanco
  • 12,960
  • 2
  • 59
  • 67
Andreea
  • 149
  • 1
  • 3
  • 10
  • A few hints: 1) To get Responses you should make your Code reproducible, see https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example. 2) More general you are looking for a dynamic UI element. Therefore you should take a look into `renderUI()`. If you have further questions go for 1) and we can help. – Tonio Liebrand Oct 23 '17 at 11:24

1 Answers1

2

You can modify a size of the plot. So that it would fit in the box. You can do like this to modify a plot size:

## In your ui, set the width to 100% in your plotOutput
 plotOutput(outputId = "ven_vs_chelt",  width = "100%")

## In your server, you specify height and width to make a plot fit in your box. You should play with height and width. So that it would fit in the box.
output$ven_vs_chelt <- renderPlot({
ggplot(ven_ch, aes(x=ven_ch$ani_tot, y=ven_chelt, fill=tip)) +
  geom_bar(stat="identity", position=position_dodge(), colour="black") +
  xlab("An") + ylab("Valoare venituri si cheltuieli(lei)") +
  scale_fill_manual(values=c("#F78181", "#81F79F"))
}, height = 300, width = 450)
Santosh M.
  • 2,356
  • 1
  • 17
  • 29
  • To be responsive, you need to get the window size. I think you should go through this question to get plot more responsive: [Responsive Plot](https://stackoverflow.com/questions/44324783/dynamically-adjust-height-and-or-width-of-shiny-plotly-output-based-on-window-si). – Santosh M. Oct 23 '17 at 15:02