我有一个闪亮的应用程序,我希望箭头在值为负时变为红色,在值为正时变为绿色,如果值为 0,则箭头变为黑色。
library(shiny)
library(shinydashboard)
library(fontawesome)
# Define UI
ui <- fluidPage(
# Application title
titlePanel("Numeric Input App"),
# Sidebar layout with input and output definitions
sidebarLayout(
# Sidebar panel for inputs
sidebarPanel(
numericInput("number", "Enter a number:", value = 0) # Numeric input field
),
# Main panel for displaying output
mainPanel(
box(
width=8,title = "ABT",status="primary",solidHeader = T,
fluidRow(
column(12,textOutput("output"),
column(2,fa("arrow-trend-up", fill = "forestgreen"))
)
))
)
)
)
# Define server logic
server <- function(input, output) {
# Function to render the output based on user input
output$output <- renderText({
paste("You entered:", input$number) # Display the entered number
})
}
# Run the application
shinyApp(ui = ui, server = server)
试试这个
library(shiny)
library(shinydashboard)
library(fontawesome)
# Define UI
ui <- fluidPage(
# Application title
titlePanel("Numeric Input App"),
# Sidebar layout with input and output definitions
sidebarLayout(
# Sidebar panel for inputs
sidebarPanel(
numericInput("number", "Enter a number:", value = 0) # Numeric input field
),
# Main panel for displaying output
mainPanel(
box(
width=8,title = "ABT",status="primary",solidHeader = T,
fluidRow(
column(12,textOutput("output"),
column(2,uiOutput("myfa"))
)
))
)
)
)
# Define server logic
server <- function(input, output) {
# Function to render the output based on user input
output$output <- renderText({
paste("You entered:", input$number) # Display the entered number
})
output$myfa <- renderUI({
if (input$number >0) {
mycolor = "forestgreen"
arw = "arrow-trend-up"
} else if(input$number == 0) {
mycolor = "black"
arw = "arrow-right"
}else {
mycolor = "red"
arw = "arrow-trend-down"
}
fa(arw, fill = mycolor)
})
}
# Run the application
shinyApp(ui = ui, server = server)