[英]Add a custom title to Shiny app with Plotly charts
I have the following Shiny application the displays a time series line chart using Plotly with 5 drop down options. 我有以下Shiny应用程序,使用带有5个下拉选项的Plotly显示时间序列折线图。 This works but I would like to add a custom title somewhere around the top of each selection. 这可行,但是我想在每个选择的顶部附近添加自定义标题。 Is there an easy way to add to this application, and if so where should I add it? 有没有简单的方法可以添加到此应用程序中,如果可以,我应该在哪里添加它?
#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)
Is there an easy way to add a custom title to each chart in this application, and if so where should I add it? 有没有一种简单的方法可以向此应用程序中的每个图表添加自定义标题,如果可以,我应该在哪里添加它?
我去了:
h_(textOutput("Title"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.