2016-10-05 2 views
0

Ich versuche, ein Grundstück in eine Box in einer glänzenden App zu legen. Die Größe der Zeichnung ändert sich so, dass ich gerade die Höhe der Box definiere, was keine Lösung ist. Ich möchte ein vertikal scrollfähiges Diagramm, das seine Breite automatisch und die Höhe der Box der Höhe des Fensters anpasst. DieseAutomatische Anpassung der Grundstücksgröße in einem rollbaren Kasten in glänzendem

ist, was ich habe versucht:

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

Dies kann durch Einstellung der Box CSS-Eigenschaften nach Ihren Bedürfnissen erfolgen. Es ist überhaupt nicht mit R verwandt. Wenn Sie beispielsweise die Höhe auf 300 px einstellen möchten, nehmen Sie diesen Code. Die restlichen Schritte können mit JavaScript/jQuery und CSS durchgeführt werden. 'box (..., style = 'display: block; width: 100%; höhe: 300px; overflow-y: scroll;')' – nilsole

Antwort

0

Dieses schaut auf meine Maschine gut.

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) 
  • Ich habe eine CSS-only-Lösung mit 85% -Ansicht-Port Höhe according to this post.
  • Aufgrund Ihrer Fluidgitter-Spalten ist eine Breite von 100% hier nicht möglich.
  • Wie bereits erwähnt, sollten Sie JavaScript/jQuery zur erweiterten Anpassung verwenden, insbesondere für ältere Browser.
  • Auch habe ich hier notwendiges tidyr-Paket hinzugefügt.

enter image description here

+0

Danke! dies macht Box Scroll-fähig, passt aber nicht automatisch die Breite von Plot und Höhe der Box an, da ich noch die Höhe der Box definieren muss. – Rajan

+0

Sie können dies mit JavaScript tun – nilsole

Verwandte Themen