简体   繁体   中英

Whitespace in rendertable output on ShinyDashboard

I am creating a table using renderTable and a plot (plotly) to be placed in 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.

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

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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