简体   繁体   English

ShinyDashboard上rendertable输出中的空格

[英]Whitespace in rendertable output on ShinyDashboard

I am creating a table using renderTable and a plot (plotly) to be placed in ShinyDashboard. 我正在使用renderTable创建一个表,并将其放置在ShinyDashboard中(作图)。 There is a whitespace that surrounds the table data that I am trying to get rid off. 有一个空格包围着我试图摆脱的表数据。 However, there is no whitespace around the plot. 但是,情节周围没有空白。

  1. How do I remove the whitespace that surround the table i have added to my shiny dashboard. 如何删除已添加到闪亮仪表板的桌子周围的空白。

  2. How do I align the header of the table "Recruitment" to the center? 如何将“招聘”表的标题与中心对齐?

I know there are some HTML solutions, but I am not familiar with those codes and will be glad if someone can explain. 我知道有一些HTML解决方案,但是我对那些代码不熟悉,如果有人可以解释,我将很高兴。

Here are my codes: 这是我的代码:

Server codes 服务器代码

    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 codes 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
  )
)
)

I would drop boxes and try grid by columns. 我会放下盒子,并尝试按列网格。 For table have a look at DT tutorials. 对于表,请查看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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM