I'm trying to make a shiny app that displays a datatable (using DT::renderDataTable) that displays comments and their sentiments. When the sentiment column (sent_score) says "Positive", I want that cell of sent_score highlighted green. When it says "Negative", I want that cell highlighted red.
If possible, I'd also be interested if there's a way to make the entire row green or red depending on if the sent_score is Positive or Negative as well.
Below is a simplified version of the dashboard's code. The problem, I think, is in the output$comments portion of the code. Thank you for your help!!
#Read in packages
library(readxl)
library(tools)
library(dplyr)
library(shiny)
library(DT)
#Read in Data
fakeshinydata
#####Build the UI for the app####
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
h4("Variables"),
selectInput(inputId = "x",
label = "Predictor:",
choices = c("ID", "ave_sentiment", "location", "title", "job_sat", "motivation", "commitment", "review"),
selected = "ID"),
selectInput(inputId = "y",
label = "Outcome:",
choices = c("sale", "ave_sentiment", "location", "title", "job_sat", "motivation", "commitment", "review"),
selected = "sale"),
mainPanel(
DT::dataTableOutput(outputId = "comments")
)
)
))
#####
#####Connect to the server for the app####
server <- function(input, output) {
fake_subset_1 <- reactive({
fakeshinydata
})
output$comments <- DT::renderDataTable({
fake_subset_1() %>%
select(input$x, input$y, comment, sent_score, com_date)
})
}
shinyApp(ui = ui, server = server)
dput
). – Stéphane Laurent