Running code before shiny render

Hi, I've got a shiny application build with the dashboard package that I'd like to embed into a markdown document.

I've written some simple code that allows me to add "?embed=true" to the querystring of the shiny app which in turn adds an "embed.css" stylesheet to remove the menus and change some styling to make it fit better in the book.

So in UI I've got:

dashboardBody(
  uiOutput('embedStylesheet'),
  blah...
)

And in server at the very top I've got:

  output$embedStylesheet = renderUI({ 
    query = getQueryString()
    if("embed" %in% names(query) && query["embed"] == "true")
    {
      tags$head(tags$link(rel = "stylesheet", type = "text/css", href = "css/embed.css"))
    }
  })

However, the problem I'm facing is that there's about a 2 second delay before the serverside script is being run, and as such you get a "flash" of the full dashboard layout that I'd like to avoid.

Can anyone suggest where I can move my code in the execution pipeline to ensure that this stylesheet is getting added to the DOM as early as possible?

Cheers,
Roy

Hi everyone. I am new in Shiny.I am trouble with publishing shiny application. As soon as Shiny app is opened, it is closed shiny app window. Codes of my shiny app is below. I

#theme_hc()
#theme_economist()
#tibble(v1=rnorm(input$n[2]))
library(ggthemes)
library(colourpicker)
ui<-dashboardPage(skin = "green",
   dashboardHeader(title = "Normal Dağılıma Uygun Örneklem Seçimi", titleWidth = 350),
      dashboardSidebar(width = 350,
       sliderInput(inputId="n", label="Örneklem Büyüklüğü",min=0, max=1000, value = c(0, 1000)),
       textInput(inputId="title", "Title of ...."),
       colourInput(inputId="color", "Renk seçiniz", value="Green"),
       actionButton(inputId = "cal", width =270 ,label = "Yenile", icon = icon("stats",lib='glyphicon'),class = "btn-info"),
       hr()),
       
       dashboardBody(
         fluidRow(
  valueBoxOutput("value1")
  ,valueBoxOutput("value2")
  ,valueBoxOutput("value3")
),
     plotOutput("box")))

server<-function(input, output, session){

#some data manipulation to derive the values of KPI boxes
input$cal
  p<-tibble(v1=rnorm(input$n[2]))
  ort <- sum(rnorm(p$v1))
  var <- var(rnorm(p$v1))
  sd<- sd(rnorm(p$v1))
  
  #creating the valueBoxOutput content
  output$value1 <- renderValueBox({
    
    valueBox(
      formatC(ort,format = "fg", width = 11, big.mark = "'"), "Toplam"
      ,icon = icon("stats",lib='glyphicon')
      ,color = "purple")
    
    
  })
  
  
  
  output$value2 <- renderValueBox({
    valueBox(formatC(var,format = "fg", width = 11, big.mark = "'"),"Ortalama"
      ,icon = icon("stats",lib='glyphicon')
      ,color = "green")
    
  })
  
  
  output$value3 <- renderValueBox({

    valueBox(
      formatC(sd,format = "fg", width = 11, big.mark = "'"),"Standart Sapma"
      ,icon = icon("stats",lib='glyphicon')
      ,color = "yellow")
    
  })
  
  
  output$box <- renderPlot({

    ggplot(p, aes(x=v1)) + 
    geom_histogram(color="black", fill=input$color)+
    geom_vline(aes(xintercept=mean(v1)),
            color="blue", linetype="dashed", size=1)+
    labs(title=input$title,x="Örneklem Büyüklüğü", y = "Frekans")+
    #paste(input$tm,"()", sep="")
    theme_economist()
    
})
}

shinyApp(ui, server)

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.