我正在尝试在 R Shiny 中制作自定义值框。我发现了如何改变背景的颜色,但是有些东西让我的值框很粗,并且在它们之间留下了很大的间隙。理想情况下,我想在一条线上显示 3,但即使宽度为 4,它们也会显得被压扁。我怎样才能让他们有更多的红色,中间只有一点白色。
library(shinydashboard)
library(shiny)
library(dplyr)
red_box_format <- ".inner , p , h3 { background-color: red};"
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
textInput(inputId = "greeting",
label = "Say hi!"),
actionButton(inputId = "submit",
label = "Submit")
),
mainPanel(
tags$style(red_box_format),
column(4,align="center",div(valueBoxOutput("total_perfect"), style= "color: #FFFFFF")),
column(4,align="center",div(valueBoxOutput("total_fails"), style= "color: #FFFFFF"))
)
))
server <- function(input, output) {
data <- tibble(name = c("Justin", "Corey", "Sibley"),
grade = c(50, 100, 100))
output$total_perfect <- renderValueBox({
shiny::req(input$greeting)
shiny::req(input$submit)
if(input$greeting == "hi!") {
num_100s <- data %>% filter(grade == 100) %>% nrow()
valueBox(value = num_100s, subtitle = "Number of Perfect Scores")
}
})
output$total_fails <- renderValueBox({
shiny::req(input$greeting)
shiny::req(input$submit)
if(input$greeting == "hi!") {
num_50s <- data %>% filter(grade == 50) %>% nrow()
valueBox(value = num_50s, subtitle = "Number of Failures")
}
})
}
shinyApp(ui, server)