闪亮的仪表板修复图的宽度

CPak

我已经用列宽指定了我的图5我的问题是,我的绘图显示的列宽更接近于2绘图之间的空白填充。

这是我的问题的 MWE

library(tidyverse)
library(shiny)
library(shinydashboard)

##----------DATA------------##
set.seed(1)
df <- map(1:4, ~data.frame(x=1:10, y=(1:10)+runif(.x), z=.x))
stat <- data.frame(A=runif(4)+2, B=runif(4)+2, depth=c(10,20,30,40))
##----------END DATA------------##

## UI
ui <- dashboardPage(
            dashboardHeader(title = "Test"),
            dashboardSidebar(
                  sidebarMenu(
                        menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard"))
                  )
            ),
            dashboardBody(
                  tabItems(
                        # First tab content
                        tabItem(tabName = "dashboard",
                              fluidRow( 
                                    box(title = "Inputs",
                                         solidHeader = TRUE,
                                         collapsible = TRUE,
                                         width = 3,    
                                     selectInput(inputId="parameter", label="Parameter", choices=c("This", "That"), selected=c("This"))
                                    )
                              ), 
                              fluidRow(
                                    column(width=5,
                                         box(title = "Plot",
                                              solidHeader = TRUE,
                                              collapsible = TRUE,
                                              plotOutput(outputId="histogram")
                                         )
                                    ),      
                            column(width=5,
                                         box(title = "Summary",
                                     plotOutput(outputId="linegraph")
                                         )
                                    )
                              )
                )
            ) # end tabitems
        ) # end dashboardbody
    ) # end dashboardpage

## SERVER
server <-   function( input, output ) {
                  # Reactive data
                  data <- reactive({ df })
                  stats <- reactive({ stat })

                  # Histogram plot
            output$histogram <- renderPlot({ ggplot() +
                                                      geom_step(data=data()[[1]], aes(x=x, y=y, colour="1"), lwd=1) + 
                                                      geom_step(data=data()[[2]], aes(x=x, y=y, colour="2"), lwd=1) +
                                                      geom_step(data=data()[[3]], aes(x=x, y=y, colour="3"), lwd=1) +
                                                      geom_step(data=data()[[4]], aes(x=x, y=y, colour="4"), lwd=1) +
                                                      scale_color_manual(values=c("1"="cyan","2"="blue","3"="green","4"="red")) +
                                                      theme_classic() +
                                                      guides(color=guide_legend(title="")) +
                                                      theme(legend.position = "bottom", legend.direction = "horizontal") + 
                                                      theme(text = element_text(size=20)) +
                                                      xlab("") + ylab("") })

                  # Linegraph plot
            output$linegraph <- renderPlot({ ggplot() +
                                                      geom_point(data=stats(), aes(x=depth, y=A, color="A"), size=5) + 
                                                      geom_line(data=stats(), aes(x=depth, y=A, color="A"), lwd=1) +
                                                      geom_point(data=stats(), aes(x=depth, y=B, color="B"), size=5) + 
                                                      geom_line(data=stats(), aes(x=depth, y=B, color="B"), lwd=1) +
                                                      geom_hline(yintercept=0, lty=2, lwd=1, color="red") +
                                                      scale_color_manual(values=c("A"="black","B"="grey")) +
                                                      theme_classic() +
                                                      guides(color=guide_legend(title="")) +
                                                      theme(legend.position = "bottom", legend.direction = "horizontal") + 
                                                      theme(text = element_text(size=20)) +
                                                      xlab("") + ylab("") })
        }

shinyApp( ui = ui, server = server )

我感谢任何帮助!

我知道

默认宽度为box()6(= 总宽度的 1/2)。但是,您的框位于宽度为 5 的列内。因此您的框的总大小为 5*0.5=2.5。

width=12当您想要列的全宽时,只需在您的框内设置即可。

这是您的固定 MWE(并替换tidyverseggplotand purrr,因为我不想污染我的 R...):

library(ggplot2)
library(purrr)
library(shiny)
library(shinydashboard)

##----------DATA------------##
set.seed(1)
df <- map(1:4, ~data.frame(x=1:10, y=(1:10)+runif(.x), z=.x))
stat <- data.frame(A=runif(4)+2, B=runif(4)+2, depth=c(10,20,30,40))
##----------END DATA------------##

## UI
ui <- dashboardPage(
  dashboardHeader(title = "Test"),
  dashboardSidebar(
    sidebarMenu(
      menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard"))
    )
  ),
  dashboardBody(
    tabItems(
      # First tab content
      tabItem(tabName = "dashboard",
              fluidRow( 
                box(title = "Inputs",
                    solidHeader = TRUE,
                    collapsible = TRUE,
                    width = 3,    
                    selectInput(inputId="parameter", label="Parameter", choices=c("This", "That"), selected=c("This"))
                )
              ), 
              fluidRow(
                column(width = 5,
                       box(title = "Plot",
                           solidHeader = TRUE,
                           collapsible = TRUE,
                           width = 12,
                           plotOutput(outputId="histogram")
                       )
                ),      
                column(width = 5,
                       box(title = "Summary",
                           width = 12,
                           plotOutput(outputId="linegraph")
                       )
                )
              )
      )
    ) # end tabitems
  ) # end dashboardbody
) # end dashboardpage

## SERVER
server <-   function( input, output ) {
  # Reactive data
  data <- reactive({ df })
  stats <- reactive({ stat })

  # Histogram plot
  output$histogram <- renderPlot({ ggplot() +
      geom_step(data=data()[[1]], aes(x=x, y=y, colour="1"), lwd=1) + 
      geom_step(data=data()[[2]], aes(x=x, y=y, colour="2"), lwd=1) +
      geom_step(data=data()[[3]], aes(x=x, y=y, colour="3"), lwd=1) +
      geom_step(data=data()[[4]], aes(x=x, y=y, colour="4"), lwd=1) +
      scale_color_manual(values=c("1"="cyan","2"="blue","3"="green","4"="red")) +
      theme_classic() +
      guides(color=guide_legend(title="")) +
      theme(legend.position = "bottom", legend.direction = "horizontal") + 
      theme(text = element_text(size=20)) +
      xlab("") + ylab("") })

  # Linegraph plot
  output$linegraph <- renderPlot({ ggplot() +
      geom_point(data=stats(), aes(x=depth, y=A, color="A"), size=5) + 
      geom_line(data=stats(), aes(x=depth, y=A, color="A"), lwd=1) +
      geom_point(data=stats(), aes(x=depth, y=B, color="B"), size=5) + 
      geom_line(data=stats(), aes(x=depth, y=B, color="B"), lwd=1) +
      geom_hline(yintercept=0, lty=2, lwd=1, color="red") +
      scale_color_manual(values=c("A"="black","B"="grey")) +
      theme_classic() +
      guides(color=guide_legend(title="")) +
      theme(legend.position = "bottom", legend.direction = "horizontal") + 
      theme(text = element_text(size=20)) +
      xlab("") + ylab("") })
}

shinyApp( ui = ui, server = server )

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

无法增加闪亮仪表板中amfunnel图表的宽度

来自分类Dev

闪亮/闪亮仪表板中的图标

来自分类Dev

闪亮的仪表板:仪表板中的粘性页脚

来自分类Dev

闪亮的仪表板:仪表板中的粘性页脚

来自分类Dev

闪亮仪表板中的条件面板

来自分类Dev

闪亮的仪表板菜单项

来自分类Dev

带闪亮仪表板的gvisGeoChart

来自分类Dev

闪亮的仪表板菜单项

来自分类Dev

R闪亮的单个图来填充整个仪表板页面

来自分类Dev

闪亮的仪表板-带有复选框值的反应条形图

来自分类Dev

仪表板显示空白图

来自分类Dev

为什么闪亮的仪表板加载时间太长?

来自分类Dev

闪亮的应用程序仪表板中的页脚对齐

来自分类Dev

增加闪亮的仪表板侧栏的长度

来自分类Dev

闪亮的仪表板无法很好地扩展

来自分类Dev

Shinyjs:闪亮仪表板中的“单击”选项

来自分类Dev

在闪亮的仪表板中更改侧边栏的字体颜色

来自分类Dev

闪亮的仪表板-动态侧边栏图标

来自分类Dev

闪亮仪表板中的高度相同的框

来自分类Dev

在闪亮的仪表板上禁用垂直滚动条

来自分类Dev

R闪亮仪表板中的动态重复条件面板

来自分类Dev

带有条件plotOut的闪亮仪表板

来自分类Dev

如何在闪亮的仪表板中使用多个slickROutput

来自分类Dev

在闪亮的仪表板上永久更改标题标题的颜色

来自分类Dev

在闪亮的仪表板上修改字体颜色

来自分类Dev

在闪亮的仪表板中关闭侧边栏

来自分类Dev

在闪亮的仪表板页眉中对齐多个操作按钮

来自分类Dev

从数据框创建闪亮的仪表板侧边栏菜单

来自分类Dev

如何在闪亮的仪表板上更改颜色?