[英]How to change the table theme in shiny
這是我的示例代碼:
library(shiny)
library(dplyr)
library(tidyr)
library(ggplot2)
library(gridExtra)
library(shinythemes)
mean_data <- data.frame(
Name = c(paste0("Group_", LETTERS[1:20])),
matx <- matrix(sample(1:1000, 1000, replace = T), nrow = 20)
)
names(mean_data)[-1] <- c(paste0("Gene_", 1:50))
sd_data <- data.frame(
Name = c(paste0("Group_", LETTERS[1:20])),
matx <- matrix(runif(1000, 5, 10), nrow = 20)
)
names(sd_data)[-1] <- c(paste0("Gene_", 1:50))
###
ui <- fluidPage(
theme = shinytheme("superhero"),
pageWithSidebar(
headerPanel("123"),
sidebarPanel(
selectInput(
"selectGeneSymbol",
"123:",
choices = colnames(mean_data)[-1],
multiple =F,
width = 400,
selected = 1
),
actionButton(inputId = "plot1", label = "FPKM"),
bsTooltip(id = "plot1", title = "Please be patient as this calculation process takes some time.", placement = "right", trigger = "hover"),
actionButton(inputId = "dataTable", label = "dataTable",width=100,class = "btn btn-primary"),
),
tags$h6(tags$a(href="https://www.ncbi.nlm.nih.gov/", "link",target = "_top"))
),
mainPanel(
plotOutput("plot"),
#uiOutput("all")
tags$style(HTML("
.dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_processing, .dataTables_wrapper .dataTables_paginate, .dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
color: #ffffff;
}
### ADD THIS HERE ###
.dataTables_wrapper .dataTables_paginate .paginate_button{box-sizing:border-box;display:inline-block;min-width:1.5em;padding:0.5em 1em;margin-left:2px;text-align:center;text-decoration:none !important;cursor:pointer;*cursor:hand;color:#ffffff !important;border:1px solid transparent;border-radius:2px}
###To change text and background color of the `Select` box ###
.dataTables_length select {
color: #0E334A;
background-color: #0E334A
}
###To change text and background color of the `Search` box ###
.dataTables_filter input {
color: #0E334A;
background-color: #0E334A
}
thead {
color: #ffffff;
}
tbody {
color: #000000;
}
"
)),
dataTableOutput('dataTable')
)
)
server <- function(input, output, session) {
## put sd into mean_data
plotdata <- eventReactive(input$plot1, {
df <- mean_data %>% mutate(sd = sd_data[,input$selectGeneSymbol])
})
p1 <- eventReactive(input$plot1, {
ggplot(data = plotdata(), aes(x = Name, y = .data[[input$selectGeneSymbol]], fill=Name,
ymin = .data[[input$selectGeneSymbol]] - sd, ymax = .data[[input$selectGeneSymbol]] + sd )) +
geom_bar(stat = "identity", position = position_dodge(0.9), width = 0.9) +
# geom_errorbar(aes(ymin = plotdata()[,input$selectGeneSymbol] - sddata()[,input$selectGeneSymbol], ymax = plotdata()[,input$selectGeneSymbol] + sddata()[,input$selectGeneSymbol]), width = .2, position = position_dodge(0.9)) +
geom_errorbar(width = .2, position = position_dodge(0.9)) +
theme_classic2() +
rotate_x_text(angle = 45) +
theme(legend.position = "none") +
labs(title = input$selectGeneSymbol, x = NULL, y = "123_value")
})
output$plot <- renderPlot({
p1()
})
output$dataTable <- DT::renderDataTable({mean_data})
}
# Create Shiny app ----
shinyApp(ui = ui, server = server)
我使用超級英雄 shiny 主題。 但這導致我的表 output 似乎不太適合 shiny 主題。
output 結果如下:
只需調整表格主題。 不要關注其他細節。
請給我一些建議。不勝感激。
我還在我的代碼中添加了表格主題。但我不知道如何更改它。
我已經自己解決了這個問題。
雖然修改后的代碼讓我感到困惑。 但我知道如何改變我想改變的地方的顏色。
library(shiny)
library(dplyr)
library(tidyr)
library(ggplot2)
library(gridExtra)
library(shinythemes)
mean_data <- data.frame(
Name = c(paste0("Group_", LETTERS[1:20])),
matx <- matrix(sample(1:1000, 1000, replace = T), nrow = 20)
)
names(mean_data)[-1] <- c(paste0("Gene_", 1:50))
sd_data <- data.frame(
Name = c(paste0("Group_", LETTERS[1:20])),
matx <- matrix(runif(1000, 5, 10), nrow = 20)
)
names(sd_data)[-1] <- c(paste0("Gene_", 1:50))
###
ui <- fluidPage(
theme = shinytheme("superhero"),
pageWithSidebar(
headerPanel("123"),
sidebarPanel(
selectInput(
"selectGeneSymbol",
"123:",
choices = colnames(mean_data)[-1],
multiple =F,
width = 400,
selected = 1
),
actionButton(inputId = "plot1", label = "FPKM"),
bsTooltip(id = "plot1", title = "Please be patient as this calculation process takes some time.", placement = "right", trigger = "hover"),
actionButton(inputId = "dataTable", label = "dataTable",width=100,class = "btn btn-primary"),
),
tags$h6(tags$a(href="https://www.ncbi.nlm.nih.gov/", "link",target = "_top"))
),
mainPanel(
plotOutput("plot"),
#uiOutput("all")
tags$style(HTML("
.dataTables_filter input {
color: #000000;
background-color: #ffffff
}
thead {
color: #ff7500;
}
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_processing,
.dataTables_wrapper .dataTables_paginate {
color: #ff7500;
}
.dataTables_wrapper .dataTables_paginate .paginate_button {
color: #ff7500 !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
color: #ff7500 !important;"
)),
dataTableOutput('dataTable')
)
)
server <- function(input, output, session) {
## put sd into mean_data
plotdata <- eventReactive(input$plot1, {
df <- mean_data %>% mutate(sd = sd_data[,input$selectGeneSymbol])
})
p1 <- eventReactive(input$plot1, {
ggplot(data = plotdata(), aes(x = Name, y = .data[[input$selectGeneSymbol]], fill=Name,
ymin = .data[[input$selectGeneSymbol]] - sd, ymax = .data[[input$selectGeneSymbol]] + sd )) +
geom_bar(stat = "identity", position = position_dodge(0.9), width = 0.9) +
# geom_errorbar(aes(ymin = plotdata()[,input$selectGeneSymbol] - sddata()[,input$selectGeneSymbol], ymax = plotdata()[,input$selectGeneSymbol] + sddata()[,input$selectGeneSymbol]), width = .2, position = position_dodge(0.9)) +
geom_errorbar(width = .2, position = position_dodge(0.9)) +
theme_classic2() +
rotate_x_text(angle = 45) +
theme(legend.position = "none") +
labs(title = input$selectGeneSymbol, x = NULL, y = "123_value")
})
output$plot <- renderPlot({
p1()
})
output$dataTable <- DT::renderDataTable({mean_data})
}
# Create Shiny app ----
shinyApp(ui = ui, server = server)
就像上面一樣:
我的代碼的重要部分在這里:
tags$style(HTML("
.dataTables_filter input {
color: #000000;
background-color: #ffffff
}
thead {
color: #ff7500;
}
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_processing,
.dataTables_wrapper .dataTables_paginate {
color: #ff7500;
}
.dataTables_wrapper .dataTables_paginate .paginate_button {
color: #ff7500 !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
color: #ff7500 !important;"
)),
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.