brtk
brtk

Reputation: 117

R Shiny - How do You present nicely column names?

My all columns contains parameters names like: "all_application", "all_phones" "all_send_forms" It doesn't look nicely in shiny tables. How do You deal with it? I would like to change it to more human names with spaces.

Upvotes: 1

Views: 1107

Answers (1)

bs93
bs93

Reputation: 1316

I usually just rename my columns as a last step in shiny before passing a dataframe to an output render:

 library(tidyverse)

df <- tibble (all_columns = 1:3,
              all_phones = c("a", "b", "c"))

df_nice_names <- df %>%
  rename("All Columns" = all_columns,
          "All Phones" = all_phones)

# A tibble: 3 x 2
  `All Columns` `All Phones`
          <int> <chr>       
1             1 a           
2             2 b           
3             3 c   

Shiny App:

library(shiny)


ui <- fluidPage(


    titlePanel(""),


    sidebarLayout(
        sidebarPanel(

        ),


        mainPanel(
           tableOutput("table")
        )
    )
)


server <- function(input, output) {

    output$table <- renderTable({
        library(tidyverse)

        df <- tibble (all_columns = 1:3,
                      all_phones = c("a", "b", "c"))

        df_nice_names <- df %>%
            rename("All Columns" = all_columns,
                   "All Phones" = all_phones)
    })

}

# Run the application 
shinyApp(ui = ui, server = server)

Upvotes: 2

Related Questions