Hello,
This is my first post ever on this forum, so I apologize if I mess something up.
Here's my problem. I have been trying to figure out how to modify a chunk of code to be able to specify exactly which color I want to have in the cells of a data table.
Here is the code:
library(shinythemes)
library(shinyWidgets)
library(shiny)
library(shinydashboard)
library(DT)
library(dplyr)
library(htmltools)
library(caret)
library(amap)
# Define UI for application
ui <- fluidPage(
tabPanel("Principal Components",
tabname="princomps",
icon=icon("compress"),
fluidPage(
sliderTextInput(inputId = "num",
label = "Number of Principal Components",
choices=c(5,4,3,2)),
DTOutput("rotations"))))
# Define server logic
server <- function(input, output) {
testrun<-reactive({
PCA<-preProcess(Chirot, method = "pca", pcaComp = input$num)
rots<-round(PCA$rotation,6)
return(rots)
})
output$rotations<-renderDT({
data<-as.data.frame(testrun())
brks <- quantile(df, probs = seq(.05, .95, .01), na.rm = TRUE)
clrs <- round(seq(305, 40, length.out = length(brks) + 1), 0) %>%
{paste0("rgb(305,", ., ",", ., ")")}
datatable(data,rownames=TRUE,options = list(lengthChange = FALSE, dom='t')) %>%
formatStyle(colnames(data), backgroundColor = styleInterval(brks, clrs))
})
}
# Run the application
shinyApp(ui = ui, server = server)
I want to be able to have a gradient of the color I choose for each separate column. I have tried tinkering with the numbers in the clrs and paste0 lines, but I don't understand how to get a specific color. So, for the sake of this example, I want to do two things:
1.) Have a gradient of green instead of red
2.) Transition the colors from blue (smaller values) to red (larger values) like a heat map
Can anyone help explain how I modify the chunk of code in the output section to acquire the desired result?
Any help would be appreciated! Thank you!