根据闪亮的小部件输入更新 ggplotly plot 的副标题
Update ggplotly plot's subtitle based on shiny widget inputs
我需要根据 shiny
小部件输入更新 shiny
应用程序中 ggplotly()
情节的字幕。但是当我试图把它放在文本里面时,它被隐藏了。
library(shiny)
library(plotly)
library(ggplot2)
ui <- fluidPage(
fluidRow(
shinyWidgets::checkboxGroupButtons(inputId = "intervals_A", label = "Bins:",
choices = c("(0.0, 10.0]", "(10.0, 70.0]", "(70.0, 330.0]", "(330.0, inf]"), selected = c("(0.0, 10.0]", "(10.0, 70.0]", "(70.0, 330.0]", "(330.0, inf]"), justified = TRUE, checkIcon = list(yes = icon("ok", lib = "glyphicon")))
),
fluidRow(plotlyOutput("plot"))
)
server <- function(input, output) {
output$plot<-renderPlotly({
p <- ggplot(ToothGrowth, aes(x = factor(dose), y = len)) +
geom_boxplot()
p <- p + labs(title = "Effect of Vitamin C on Tooth Growth",
subtitle = "Plot of length by dose"
)
ggplotly(p)%>%
layout(title = list(text = paste0('Effect of Vitamin C on Tooth Growth"',
'<br>',
'<sup>',
'Plot of length by'),paste0(input$intervals_A) ,paste0('interval','</sup>')))
})
}
shinyApp(ui, server)
写一个全局 paste
作为包装器。为了粘贴多个选择,我为 input$intervals_A
添加了逗号
library(shiny)
library(plotly)
library(ggplot2)
ui <- fluidPage(
fluidRow(
shinyWidgets::checkboxGroupButtons(inputId = "intervals_A", label = "Bins:",
choices = c("(0.0, 10.0]", "(10.0, 70.0]", "(70.0, 330.0]", "(330.0, inf]"), selected = c("(0.0, 10.0]", "(10.0, 70.0]", "(70.0, 330.0]", "(330.0, inf]"), justified = TRUE, checkIcon = list(yes = icon("ok", lib = "glyphicon")))
),
fluidRow(plotlyOutput("plot"))
)
server <- function(input, output) {
output$plot<-renderPlotly({
p <- ggplot(ToothGrowth, aes(x = factor(dose), y = len)) +
geom_boxplot()
p <- p + labs(title = "Effect of Vitamin C on Tooth Growth",
subtitle = "Plot of length by dose"
)
ggplotly(p)%>%
layout(title = list(text = paste(paste0('Effect of Vitamin C on Tooth Growth"',
'<br>',
'<sup>',
'Plot of length by'),paste0(input$intervals_A,collapse = ',') ,paste0('interval','</sup>'))))
})
}
shinyApp(ui, server)
我需要根据 shiny
小部件输入更新 shiny
应用程序中 ggplotly()
情节的字幕。但是当我试图把它放在文本里面时,它被隐藏了。
library(shiny)
library(plotly)
library(ggplot2)
ui <- fluidPage(
fluidRow(
shinyWidgets::checkboxGroupButtons(inputId = "intervals_A", label = "Bins:",
choices = c("(0.0, 10.0]", "(10.0, 70.0]", "(70.0, 330.0]", "(330.0, inf]"), selected = c("(0.0, 10.0]", "(10.0, 70.0]", "(70.0, 330.0]", "(330.0, inf]"), justified = TRUE, checkIcon = list(yes = icon("ok", lib = "glyphicon")))
),
fluidRow(plotlyOutput("plot"))
)
server <- function(input, output) {
output$plot<-renderPlotly({
p <- ggplot(ToothGrowth, aes(x = factor(dose), y = len)) +
geom_boxplot()
p <- p + labs(title = "Effect of Vitamin C on Tooth Growth",
subtitle = "Plot of length by dose"
)
ggplotly(p)%>%
layout(title = list(text = paste0('Effect of Vitamin C on Tooth Growth"',
'<br>',
'<sup>',
'Plot of length by'),paste0(input$intervals_A) ,paste0('interval','</sup>')))
})
}
shinyApp(ui, server)
写一个全局 paste
作为包装器。为了粘贴多个选择,我为 input$intervals_A
library(shiny)
library(plotly)
library(ggplot2)
ui <- fluidPage(
fluidRow(
shinyWidgets::checkboxGroupButtons(inputId = "intervals_A", label = "Bins:",
choices = c("(0.0, 10.0]", "(10.0, 70.0]", "(70.0, 330.0]", "(330.0, inf]"), selected = c("(0.0, 10.0]", "(10.0, 70.0]", "(70.0, 330.0]", "(330.0, inf]"), justified = TRUE, checkIcon = list(yes = icon("ok", lib = "glyphicon")))
),
fluidRow(plotlyOutput("plot"))
)
server <- function(input, output) {
output$plot<-renderPlotly({
p <- ggplot(ToothGrowth, aes(x = factor(dose), y = len)) +
geom_boxplot()
p <- p + labs(title = "Effect of Vitamin C on Tooth Growth",
subtitle = "Plot of length by dose"
)
ggplotly(p)%>%
layout(title = list(text = paste(paste0('Effect of Vitamin C on Tooth Growth"',
'<br>',
'<sup>',
'Plot of length by'),paste0(input$intervals_A,collapse = ',') ,paste0('interval','</sup>'))))
})
}
shinyApp(ui, server)