Is there a way of getting renderValueBox() to be compatible with Shiny Theme?

185 views Asked by At

I'm currently developing a dashboard that displays value boxes that are either green or red depending if they're positive/negative. This functions perfectly without using shiny themes but as soon as I use it I lose the color in the value box and it just uses the primary colour of the theme. Any help would be really appreciated.

library(shiny)
library(shinydashboard)
library(RPostgreSQL)
library(DT)
library(RPostgres) 
library(dplyr) 
library(highcharter)
library(formattable)
library(ggplot2)
library(shinythemes)  


data = read.csv('nazare_dash_data2.csv') 
colnames(data)[which(names(data) == "X")] <- "Date"
data$Date = as.Date(data$Date,tryFormats = c("%Y-%m-%d", "%Y/%m/%d"))

 ui = fluidPage(theme = shinytheme("cyborg"),

                   dashboardHeader(title = 'Nazare Point Ltd.'),
                   dashboardSidebar(disable = TRUE),
                   dashboardBody(
                     
#------------------------  DAILY BOX -------------------------------------------
                     box(title = 'Daily', width = 12, collapsible = TRUE,
                        tabBox(width = 12,height = 12,
                        tabPanel('Data',
                     column(width = 3,
                            selectInput(inputId = 'Date',label = 'Date',choices = unique(data$Date),multiple = FALSE)
                            ),
                     
                     
                     column(width = 3,
                            valueBoxOutput('Realised_Options',width = 12),
                            valueBoxOutput('Realised_Futures',width = 12)
                     ),
                     column(width = 3,
                            valueBoxOutput('Unrealised_Options',width = 12),
                            valueBoxOutput('Unrealised_Futures',width = 12),
                            valueBoxOutput('Fees',width = 12)
                            
                     ), 
                     column(width = 3,
                            valueBoxOutput('Options_Total',width = 12),
                            valueBoxOutput('Futures_Total',width = 12),
                            valueBoxOutput('PNL',width = 12)
                            )
                     
                        ),
                         tabPanel('Plots')
                        )
                     ) ,
                    
                     
                     
                     
#-----------------------BOX YEAR TO DATE ---------------------------------------
                    box(width = 12, title = 'Year To Date', collapsible = TRUE,
                        column(width = 4,
                               valueBoxOutput('YTD_PNL',width =12),
                               valueBoxOutput('YTD_Fees',width =12)
                               ),
                        column(width = 8,
                               plotOutput('ytd_pnl',width = "100%")
                               )
                        
                    ),
                     
#----------------------- DATATABLE BOX------------------------------------------
                    box(width = 12,collapsible = TRUE,
                         DT::dataTableOutput(outputId = "table")
                         )
                     
                   
                     
                     ) # </dashboardBody>
                   
                   
                   ) # </dashboardPage>
                   



server = function(input,output){thematic::thematic_shiny()
  
  filtered_data = reactive({
    data = filter(data, Date == input$Date) 
    return(data)
  }) 
  
  color_pnl = function(x){
    if(x > 0){
      color = 'green'
    } 
    else{
      color = 'red'
    }
    return(color)
  }
# ----------------------- DAILY OUTPUTS ----------------------------------------
  
  output$Realised_Options = renderValueBox({
    valueBox(paste(prettyNum(filtered_data()[,c('OptRlzd')],big.mark=",",scientific=FALSE)),
             'Options Realised',
             color = color_pnl(filtered_data()[,c('OptRlzd')]))
  })
  
  output$Realised_Futures = renderValueBox({
    valueBox(paste(prettyNum(filtered_data()[,c('FutRlzd')],big.mark=",",scientific=FALSE)),
             'Futures Realised',
             color = color_pnl(filtered_data()[,c('FutRlzd')]))
  })
  
  output$Unrealised_Options = renderValueBox({
    valueBox(paste(prettyNum(filtered_data()[,c("OptionsEDFOpenEq")],big.mark=",",scientific=FALSE)),
             'Options Unrealised',
             color = color_pnl(filtered_data()[,c("OptionsEDFOpenEq")]))
  }) 
  
  output$Unrealised_Futures = renderValueBox({
    valueBox(paste(prettyNum(filtered_data()[,c("EDFCalcOpenEq")],big.mark=",",scientific=FALSE)),
             'Futures Unrealised',
             color = color_pnl(filtered_data()[,c("EDFCalcOpenEq")]))
  })
  
  output$Options_Total = renderValueBox({ 
    valueBox(paste(prettyNum((filtered_data()[,c("OptionsEDFOpenEq")] + filtered_data()[,c('OptRlzd')]),big.mark=",",scientific=FALSE)),
             'Total Options',
             color = color_pnl(filtered_data()[,c("OptionsEDFOpenEq")]))
    }) 
  
  output$Futures_Total = renderValueBox({ 
    valueBox(paste(prettyNum((filtered_data()[,c("EDFCalcOpenEq")] + filtered_data()[,c('FutRlzd')]),big.mark=",",scientific=FALSE)),
             'Total Futures',
             color = color_pnl(filtered_data()[,c("OptionsEDFOpenEq")]))
  })
  
  output$PNL = renderValueBox({
    valueBox(paste(prettyNum(filtered_data()[,c('PL')],big.mark=",",scientific=FALSE)),
                   'Total PNL (Net Fees)',
                   color = color_pnl(filtered_data()[,c('PL')]))
  })
  
  
  output$Fees = renderValueBox({
    valueBox(paste(filtered_data()[,c('Fees')]),'Fees')
  })
  
#------------------------YEAR TO DATE OUTPUTS-----------------------------------
  
  
  output$YTD_PNL = renderValueBox({
    valueBox(paste(prettyNum(sum(data$PL),big.mark=",",scientific=FALSE)),
             'PNL',
             color = color_pnl(sum(data[,c('PL')]))) 
  })
  
  output$YTD_Fees = renderValueBox({
    valueBox(paste(prettyNum(sum(data$Fees),big.mark=",",scientific=FALSE)),
             'Fees',
             color = 'red')
  })
  
  
  output$ytd_pnl = renderPlot({
    ggplot(data=data, aes(Date,cumsum(PL))) + geom_line(colour = "#009E73") + geom_point()
  })
  
# ------------------------------------------------------------------------------ 
  output$table = DT::renderDataTable(DT::datatable(style = "bootstrap",{ 
   data
  }))

  

  
  
}
shinyApp(ui,server)
0

There are 0 answers