2017-10-23 3 views
0

상자에 표시하는 플롯이 있는데 상자의 크기를 수정하고 싶지만 플롯이 box보다 큽니다. 두 가지를 모두 수정하여 플롯이 남아 있도록하려면 어떻게해야합니까? 상자에 맞습니까?R 반짝이 플롯 크기

#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")) 
    }) 
+0

몇 가지 힌트 : 당신은 플롯 크기 수정 같이 할 수있는 1) 재현 코드를해야 응답을 얻으려면을, https://stackoverflow.com/questions/5963269/how-to- 참조 make-a-great-r-reproducible-example을 사용합니다. 2) 더 일반적인 당신은 동적 UI 요소를 찾고 있습니다. 그러므로'renderUI()'를 살펴보아야한다. 추가 질문이 있으시면 1)을 참조하십시오. – BigDataScientist

답변

0

플롯의 크기를 수정할 수 있습니다. 상자에 들어갈 수 있도록.

## 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) 
+0

응답 성이 좋으려면 창 크기를 가져와야합니다. 나는 당신이이 질문을 통해 더 반응하는 줄거리를 가져야한다고 생각합니다. [Responsive Plot] (https://stackoverflow.com/questions/44324783/dynamically-adjust-height-and-or-width-of-shiny-plotly-output -based-on-window-si). – Santosh

관련 문제