I am desperate to change the default colors for the rpivotTable package. I also posted the problem on github of the package creator, but no one has answered yet, so if anyone has an idea how to solve this problem, I would be more than grateful.
My main problem is changing the blue colors in the rectangles below the variable selection: Example
Using this function that I found on the Internet, I manage to change the whole background, but not the specific thing I want (outside of Shiny only so far):
style_widget <- function(hw=NULL, style="", addl_selector="") {
stopifnot(!is.null(hw), inherits(hw, "htmlwidget"))
elementId <- hw$elementId
if(is.null(elementId)) {
elementId <- sprintf(
'htmlwidget-%s',
htmlwidgets:::createWidgetId()
)
hw$elementId <- elementId
}
htmlwidgets::prependContent(
hw,
htmltools::tags$style(
sprintf(
"#%s %s {%s}",
elementId,
addl_selector,
style
)
)
)
}
pivot_graph<-rpivotTable(mtcars)
browsable(
tagList(
style_widget(hw=pivot_graph, "background-color: rgb(245, 245, 245);", "table td")
)
)
However, when I try to do this Shiny, I can’t understand what to put where and how to do it (or even if it is even possible with this function). Any help is appreciated. My brilliant code:
library(shiny)
library(rpivotTable)
library(rvest)
ui <- fluidPage(
titlePanel("Cars"),
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Choose CSV File',
accept=c('text/csv','text/comma-separated-values,text/plain','.csv')),
actionButton("save1","Save Table 1")
),
mainPanel(
tabsetPanel(
tabPanel("Pivot Table 1",
rpivotTableOutput("table")),
tabPanel("Pivot Table 2",
rpivotTableOutput("table2"))
)
)
)
)
server <- function(input, output,session)
{
session$onSessionEnded(stopApp)
observe({
file1 = input$file1
if (is.null(file1)) {
return(NULL)
}
st_data <<- read.csv(file1$datapath)
output$table <- renderRpivotTable({
rpivotTable(mtcars,
rendererName="Table",
onRefresh = htmlwidgets::JS("function(config) {Shiny.onInputChange('myData',
document.getElementById('table').innerHTML); }")
)
})
output$table2 <- renderRpivotTable({
rpivotTable(mtcars,aggregatorName="Average",
rendererName="Table",
onRefresh = htmlwidgets::JS("function(config) {Shiny.onInputChange('myData',
document.getElementById('table').innerHTML); }")
)
})
summarydf <- eventReactive(input$myData,{
input$myData %>%
read_html %>%
html_table(fill = TRUE) %>%
.[[2]]
})
observeEvent(input$save1, {
if(nrow(summarydf() )<1) return()
write.csv(summarydf(), file="./cars1.csv")
})
})
}
shinyApp(ui = ui, server = server)