Css for shiny in a function

Hello,

I am trying to write a function which automatically loads a CSS into a shiny app as the shinytheme function from the shinythemes package, which has the following code:


shinythemes::shinytheme
function (theme = NULL) *
{
   if (is.null(theme) || !theme %in% allThemes()) {*
        stop(theme, " is not an available theme. Valid themes are: ", *
           paste(allThemes(), collapse = ", "), ".")*
    }
   paste0("shinythemes/css/", theme, ".min.css")*
}

I tried to modify it and write my own function, which has solely one theme file as an inout, and is therefore a function without an argument (so I do not need the if (is.null(theme) || !theme %in% allThemes()) {... part), I saved a CSS named mytheme.min.css in the given folder
example:

mytheme <- function () 
{

 paste0("C:\\Users\\Me\\Documents\\", "mytheme", ".min.css")*
}

I tried it with a shinyApp, but unfortunately this does not work and it loads with the default theme

ui <- fluidPage(
  theme = mytheme(),

  titlePanel("Hello Shiny!"),
  
 sidebarLayout(
    
sidebarPanel(
      

      sliderInput(inputId = "bins",
                  label = "Number of bins:",
                  min = 1,
                  max = 50,
                  value = 30)
      
    ),
    

    mainPanel(
      

      plotOutput(outputId = "distPlot")
      
    )
  )
)

server <- function(input, output) {
  

  output$distPlot <- renderPlot({
    
    x    <- faithful$waiting
    bins <- seq(min(x), max(x), length.out = input$bins + 1)
    
    hist(x, breaks = bins, col = "#75AADB", border = "white",
         xlab = "Waiting time to next eruption (in mins)",
         main = "Histogram of waiting times")
    
  })
  
}

shinyApp(ui, server)

If someone could tell what I have to change in order to make this work, I would be grateful.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.