ShinyDashboard上rendertable输出中的空格

时间:2018-12-24 03:49:37

标签: r shiny whitespace

我正在使用renderTable创建一个表格,并将其放置在ShinyDashboard中。有一个空格包围着我试图摆脱的表数据。但是,情节周围没有空白。

  1. 如何删除已添加到闪亮仪表板的桌子周围的空白。

  2. 如何将“招聘”表的标题与中心对齐?

我知道有一些HTML解决方案,但是我对那些代码不熟悉,如果有人可以解释,我将很高兴。

这是我的代码:

服务器代码

    output$recruit_stats <- renderTable(recruit_stats, bordered = TRUE, colnames = TRUE)

  output$Recruitment_bar_plot <- renderPlotly({
    Recruitment_bar<-Recruitment_bar[(Recruitment_bar$hospital!="H"),];

    R01 <- ggplot()+
      geom_bar(data=Recruitment_bar,aes(x=hospital,y=count),stat = "identity", fill="navyblue")+ 
      ylim(0,1200) + 
      geom_text(data=Recruitment_bar,aes(x=hospital,y=count*1.05,label=paste(count)),size=2.5, vjust=-1.0) +
      theme(panel.background = element_blank(), 
            axis.text = element_text(size = 7),
            axis.title = element_text(size=7),
            axis.line = element_line(colour = "black", size = 0.5, linetype = "solid"), 
            plot.title = element_text(size=8, face="bold", hjust=0.5), 
            legend.position = "none", legend.text = element_text(size=6)) +
      labs(fill="") + guides(fill = guide_legend(reverse=TRUE))+
      ylab("No. Recruited") + ggtitle("No. of Patients Recruited (Jan 2017 to June 2018)") 


    ggplotly(R01, tooltip=c("count"));
  })

UI代码

Recruitment<-tabItem(
  tabName = "Recruitment",
  fluidRow(
    box(
      box(title = "Recruitment", 
          status = "primary", 
          solidHeader = TRUE,column(12,tableOutput("recruit_stats"), align="c"),
          width=8,
          collapsed=TRUE)
  ),
  box(
    plotlyOutput("Recruitment_bar_plot", height = 400),
    width=5,
    status = "primary",
    solidHeader = TRUE
  )
)
)

1 个答案:

答案 0 :(得分:0)

我会放下盒子并尝试按列进行网格化。有关表格,请查看DT教程。

library(shiny)
library(shinydashboard)

dat5 <- c(rep("Female", 3376), rep("Male", 2180))
app <- shinyApp(
ui <- shinyUI(
  dashboardPage(dashboardHeader(title = "PSM"),
                dashboardSidebar(),
                dashboardBody(
                  tabItem(
                    tabName = "Recruitment",
                    fluidRow(

                        column(width=6, 
                               DT::dataTableOutput("recruit_stats")),
                        column(width=6, 
                               plotOutput("pie_chart", height = 400))

                    )
                  )
                  ))
                    ),

                      server <- shinyServer(function(input,output){  
                        output$pie_chart <- renderPlot({
                          df <- table(dat5)
                          cols <- rainbow(length(df))
                          barplot(df, col = cols)

                        })
                        output$recruit_stats <- DT::renderDataTable({
                          DT::datatable(as.data.frame(dat5), options = list(paging=TRUE, searching= TRUE ))
                        })
                           })
)

runApp(app)