【发布时间】:2021-11-03 17:42:51
【问题描述】:
我需要根据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)
【问题讨论】: