【发布时间】:2021-10-24 09:13:16
【问题描述】:
我目前正在探索 Shiny 中的 Plotly 输出,并且想知道是否有一种方法可以删除和重命名当您将鼠标悬停在每个观察值上时出现的信息。我在网站上看到了一些示例,但没有一个可以直接使用插入到 renderPlotly() 中的 ggplot 图表
就我而言,我正在尝试删除年份信息并将计数重命名为计数。有什么建议吗?
示例代码:
library(shiny)
library(tidyverse)
library(plotly)
A <- structure(list(Year = c(2020, 2021, 2021), Size = c(
"L", "M",
"S"
), count = c(83L, 93L, 216L)), row.names = c(NA, -3L), groups = structure(list(
Year = c(2020, 2021), .rows = structure(list(1L, 2:3), ptype = integer(0), class = c(
"vctrs_list_of",
"vctrs_vctr", "list"
))
), row.names = c(NA, -2L), class = c(
"tbl_df",
"tbl", "data.frame"
), .drop = TRUE), class = c(
"grouped_df",
"tbl_df", "tbl", "data.frame"
))
ui <- fluidPage(
titlePanel("Test Remove/Rename"),
sidebarLayout(
sidebarPanel(),
mainPanel(
plotlyOutput(outputId = "test")
)
)
)
server <- function(input, output) {
output$test <- renderPlotly({
ggplot(A, aes(Year, count, fill = Size)) +
geom_col()
})
}
shinyApp(ui = ui, server = server)
【问题讨论】: