r - 使用 Plotly 图表向 Shiny 应用程序添加自定义标题
问题描述
我有以下 Shiny 应用程序,它使用带有 5 个下拉选项的 Plotly 显示时间序列折线图。这可行,但我想在每个选择的顶部附近添加一个自定义标题。有没有一种简单的方法可以添加到这个应用程序中,如果有,我应该在哪里添加它?
#Import libraries
library(shiny)
library(plotly)
library(tidyr)
library(bindrcpp)
# Define UI for application that draws a histogram
ui <- bootstrapPage(
selectInput(inputId = "n_breaks",
label = "Select Data:",
choices = c("Distinct_FLD","Not_On_MM","API_Call_Count","Cost","CACHE_Count"),
selected = "Distinct_FLD"),
plotlyOutput(outputId = "main_plot", height = "600px")
)
# Define server logic required to draw a histogram
server <- function(input, output) {
#Import data
df = read.csv("API_Statistics.csv")
output$main_plot <- renderPlotly({
if (input$n_breaks == "Distinct_FLD") {
#Create variable X getting rid of NA values
x <- df$Date[!is.na(df$Distinct_FLD)]
#Create variable Y getting rid of NA values
y <- df$Distinct_FLD[!is.na(df$Distinct_FLD)]
#Plotly plot
plot_ly(x = x, y = y, type = 'scatter', mode = 'lines')
}
else if (input$n_breaks == "Not_On_MM") {
#Create variable X getting rid of NA values
x <- df$Date[!is.na(df$Not_On_MM)]
#Create variable Y getting rid of NA values
y <- df$Not_On_MM[!is.na(df$Not_On_MM)]
#Plotly plot
plot_ly(x = x, y = y, type = 'scatter', mode = 'lines')
}
else if (input$n_breaks == "API_Call_Count") {
#Create variable X getting rid of NA values
x <- df$Date[!is.na(df$API_Call_Count)]
#Create variable Y getting rid of NA values
y <- df$API_Call_Count[!is.na(df$API_Call_Count)]
#Plotly plot
plot_ly(x = x, y = y, type = 'scatter', mode = 'lines')
}
else if (input$n_breaks == "Cost") {
#Create variable X getting rid of NA values
x <- df$Date[!is.na(df$Cost)]
#Create variable Y getting rid of NA values
y <- df$Cost[!is.na(df$Cost)]
#Plotly plot
plot_ly(x = x, y = y, type = 'scatter', mode = 'lines')
}
else if (input$n_breaks == "CACHE_Count") {
#Create variable X getting rid of NA values
x <- df$Date[!is.na(df$CACHE_Count)]
#Create variable Y getting rid of NA values
y <- df$CACHE_Count[!is.na(df$CACHE_Count)]
#Plotly plot
plot_ly(x = x, y = y, type = 'scatter', mode = 'lines')
}
})
}
# Run the application
shinyApp(ui = ui, server = server)
有没有一种简单的方法可以为这个应用程序中的每个图表添加自定义标题,如果有,我应该在哪里添加它?
解决方案
我去了:
h_(textOutput("Title"))
推荐阅读
- python - 升级 pandas 破坏了 Conda/numpy 依赖项
- c - unsigned int vs signed int 存储值的相关性
- java - 为 H2 设置默认的小数精度和小数位数
- php - 如何用 php-opencloud 搁置实例?
- c# - 带有 C# 的 MongoDB 对 String 数据类型的所有字段使用 Filter.Regex 来查找与正则表达式匹配的文档
- neural-network - 将神经网络权重偏向大的正值
- python - 如何在熊猫数据框列中插入逗号作为值分隔符?
- reactjs - 删除后从屏幕上删除项目
- avfoundation - AVFoundation AVCaptureVideoPreviewLayer 在几个小时后冻结
- elasticsearch - Filebeat 7.10 无法从多个 kubernetes pod 收集事件