2016-10-05 3 views
0

반짝 이는 응용 프로그램의 상자 안에 플롯을 넣으려고합니다. 플롯의 크기가 변경되어 현재 상자의 높이를 정의하고 있는데 이는 해결책이 아닙니다. 자동으로 너비를 조정하고 창 높이와 상자 높이를 같게 세로로 스크롤 할 수있는 플롯이 필요합니다.반짝이는 상자에서 플롯 크기를 자동으로 조정하십시오.

이 내가 시도 것입니다 :

library(shiny) 
library(shinydashboard) 

ui <-dashboardPage(
    dashboardHeader(), 
    dashboardSidebar(sidebarMenu(
    menuItem("Box Plot", tabName = "boxplot") 
)), 
    dashboardBody(
    tabItems(tabItem(tabName = "boxplot", 
        fluidPage(fluidRow(column(4), 
             column(8, box(title = "Box Plot", width = NULL, 
                solidHeader = TRUE, status = "primary", collapsible = TRUE, 
                plotOutput("plot1", inline=F, width="100%", height=1500), style = 'overflow-y: scroll;') 
               ))))))) 

server <- shinyServer(function(input, output, session) { 
    output$plot1 <- renderPlot({ 
    x <- data.frame(matrix(rnorm(1000), ncol = 20)) 
    input_data <- rnorm(ncol(x)) 
    d <- data.frame(x) 
    plot.data <- gather(d, variable, value) 
    plot.data$test_data <- as.numeric(rep(input_data, each = nrow(x))) 

    p = ggplot(plot.data, aes(x = 0, y=value)) + 
     geom_boxplot() + 
     geom_point(aes(x = 0, y = test_data), color = "red") + 
     facet_wrap(~variable, scales = "free_y", switch = "y", nrow = 1) + 
     xlab("") + ylab("") + 
     theme(legend.position="none") + theme_bw() + theme(axis.text.x=element_blank(), 
                 axis.text.y=element_text(angle=90), 
                 axis.ticks.x=element_blank()) 

    print(p, vp=viewport(angle=270, width = unit(3, "npc"), height = unit(0.32, "npc"))) 
    }) 
}) 

shinyApp(ui = ui, server = server) 
+0

이 필요에 따라 상자의 CSS 속성을 조정하여 수행 할 수 있습니다. 그것은 R과 전혀 관계가 없습니다. 예를 들어, 높이를 300px로 설정하려면이 코드를 사용하십시오. 나머지 단계는 JavaScript/jQuery 및 CSS를 사용하여 수행 할 수 있습니다. '상자 (..., 스타일 ='표시 : 블록, 너비 : 100 %, 높이 : 300px, 오버플로 - y : 스크롤; ')' – nilsole

답변

0

이 사람은 내 컴퓨터에 좋아 보인다.

library(shiny) 
library(shinydashboard) 
library(tidyr) 

ui <-dashboardPage(
    dashboardHeader(), 
    dashboardSidebar(sidebarMenu(
    menuItem("Box Plot", tabName = "boxplot") 
)), 
    dashboardBody(
    tabItems(tabItem(tabName = "boxplot", 
        fluidPage(fluidRow(column(4), 
             column(8, box(title = "Box Plot", width = NULL, 
                 solidHeader = TRUE, status = "primary", collapsible = TRUE, 
                 plotOutput("plot1", inline=F, width="100%", height=1500), style = 'display:block;width:100%;height:85vh;overflow-y: scroll;') 
             ))))))) 

server <- shinyServer(function(input, output, session) { 
    output$plot1 <- renderPlot({ 
    x <- data.frame(matrix(rnorm(1000), ncol = 20)) 
    input_data <- rnorm(ncol(x)) 
    d <- data.frame(x) 
    plot.data <- gather(d, variable, value) 
    plot.data$test_data <- as.numeric(rep(input_data, each = nrow(x))) 

    p = ggplot(plot.data, aes(x = 0, y=value)) + 
     geom_boxplot() + 
     geom_point(aes(x = 0, y = test_data), color = "red") + 
     facet_wrap(~variable, scales = "free_y", switch = "y", nrow = 1) + 
     xlab("") + ylab("") + 
     theme(legend.position="none") + theme_bw() + theme(axis.text.x=element_blank(), 
                 axis.text.y=element_text(angle=90), 
                 axis.ticks.x=element_blank()) 

    print(p, vp=viewport(angle=270, width = unit(3, "npc"), height = unit(0.32, "npc"))) 
    }) 
}) 

shinyApp(ui = ui, server = server) 
  • 나는 85 %의 뷰 포트 높이 according to this post와 CSS 전용 솔루션을 만들었습니다.
  • 유체 격자 열 때문에 100 % 너비가 여기에 없습니다.
  • 위에서 언급 한 바와 같이 고급 조정, 특히 구식 브라우저의 경우 JavaScript/jQuery를 사용하는 것이 좋습니다.
  • 또한 여기에 필요한 깔끔한 패키지를 추가했습니다.

enter image description here

+0

고마워! 이것은 상자를 스크롤 할 수있게하지만 상자의 높이를 정의해야하므로 상자의 플롯 및 높이의 너비를 자동으로 조정하지는 않습니다. – Rajan

+0

JavaScript로이를 수행 할 수 있습니다. – nilsole

관련 문제