【发布时间】:2019-05-08 14:51:53
【问题描述】:
我正在尝试制作一个显示 cmets 及其情绪的数据表(使用 DT::renderDataTable)的闪亮应用程序。当情绪列 (sent_score) 显示“积极”时,我希望 sent_score 的那个单元格突出显示为绿色。当它显示“否定”时,我希望该单元格以红色突出显示。
如果可能的话,如果有办法根据 sent_score 是 Positive 还是 Negative 使整行变为绿色或红色,我也会感兴趣。
以下是仪表板代码的简化版本。我认为问题出在代码的 output$cmets 部分。谢谢你的帮助!!
#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)。
标签: r colors shiny dashboard dt