I have a very simple shiny app that is makes a gt table using some inputs.
One of my goals is to pass a user input which is numeric into the cols_width() argument so I can add padding to my first column. Although when doing something like the following I get an error that the input is not found.
output$table <- render_gt(
reactive_tab() %>%
gt() %>%
cols_width(
1 ~ px(input$colpad)
)
)
I've also tried doing {input$colpad} and .(input$colpad) with no success either.
Here is the code:
library(data.table)
library(shiny)
library(gt)
library(shinyscreenshot)
data <- gtcars %>% head(10) %>%
select(mfr, model, msrp)
ui <- navbarPage("Y u no pad??",
tabPanel("Table", icon = icon("table"),
sidebarLayout(
sidebarPanel(
selectInput("input",
label = "Choose mfr",
choices = c("All", data$mfr)),
numericInput("colpad", label = "First Column Padding", min = 1, max = 10000, value = 150),
screenshotButton(selector="#table", label = 'Download Png', filename = 'screenshot'),
),
mainPanel(
gt_output("table")
)
)
)
)
server <- function(input, output, session) {
reactive_tab <- reactive({
d <- data
if(input$input != "All")
d <- subset(d, cyl == input$input)
d
})
output$table <- render_gt(
reactive_tab() %>%
gt() %>%
cols_width(
1 ~ px(input$colpad)
)
)
}
shinyApp(ui, server)

