-1

I've searched and searched and just can't find a suitable example. I'm not really a developer by trade, so its possible I came across the answer I need but just didn't understand it.

I'm using R to manipulate/analyze some data and then producing a report in Rmarkdown, using flex-dashboard as the output. I have a wide table with several columns (i.e. the columns are application name and data center locations, I then show a count of host names per app in each site) and would like to angle/rotate some of them so the table is more readable and fits better on the page.

I'm not married to any one solution; I've looked for answers using kable, xtable, htmltable, etc. but can't seem to find what I need. I simply want to turn some of the table column names at an angle.

I'm not providing any reproducible data because it not about the data but rather formatting of the table output. Looking for any suggestion. Thanks much.

BR917
  • 1
  • 2
    you should still produce something minimal to respect the time and effort of others so they don't have to mock up a full solution for you on their own time. – hrbrmstr Jun 13 '17 at 13:47

1 Answers1

0

I would not recommend pixiedust if your table has thousands of rows, because the string manipulations can take quite a while as the table grows. But if you are less than a few hundred, this should be a reasonable option.

library(shiny)
library(pixiedust)

options(pixiedust_print_method = "html")

shinyApp(
  ui = shinyUI(
    fluidPage(
      uiOutput("table")
    )
  ),

  server = shinyServer(function(input, output, session){

    output$table <- 
      renderUI({
        dust(mtcars) %>%
          sprinkle_colnames(mpg = "Miles per Gallon",
                            cyl = "Cylinders") %>%
          sprinkle(rotate_degree = -45,
                   height = 70,
                   height_units = "pt",
                   part = "head") %>%
          sprinkle(pad = 3) %>%
          medley_bw() %>%
          print(asis = FALSE) %>%
          HTML()
      })
  })
)
Benjamin
  • 16,897
  • 6
  • 45
  • 65
  • Benjamin, thank you. As you stated, I don't need help with shaping the data, just rotating the header text. Your solution works well, thanks. One follow-up, is there a way to rotate some of the column names but not others. For example, in your sample leave "Miles per Gallon" 'flat', but turn the remaining labels at 45%? – BR917 Jun 13 '17 at 14:23
  • The `sprinkle` function takes `rows` and `cols` arguments that designate which cells should be altered. You could use, for examples `sprinkle(cols = c(3, 5, 7), rotate_degree = -45)` and only the third, fifth, and seventh columns would be affected. See `?sprinkle` for full details – Benjamin Jun 13 '17 at 14:27
  • Perfect. I'll give that a try. Thanks much. – BR917 Jun 13 '17 at 14:29