【发布时间】:2021-06-25 20:03:58
【问题描述】:
我正在尝试在工具提示中显示一个绘图。我只希望当我悬停在 mpg 行上方时显示工具提示。我试图实现这样的目标:https://laustep.github.io/stlahblog/posts/DTqTips.html,但没能实现。下面是我要显示的情节的代表解决方案。
library(shiny)
library(DT)
library(tidyverse)
shinyApp(
ui = fluidPage(
selectInput('cylSelect', choices = c(4,6,8), label ="Select the # of cylinders"),
dataTableOutput('table'),
),
server = function(server, input, output) {
cars <- reactive({
mtcars %>%
filter(cyl == input$cylSelect) %>%
group_by(am) %>%
summarise(across(everything(), mean))
})
p <- renderPlot({
cars() %>%
ggplot(aes(x = am, y=mpg)) +
geom_bar(stat = 'identity')
})
output$table <- renderDataTable({
datatable(cars()
)
})
}
)
【问题讨论】:
标签: r ggplot2 shiny datatables