R 闪亮的仪表板-带有复选框中的值的反应条形图
根据我的数据,我可以准备一个简单的道奇条形图R 闪亮的仪表板-带有复选框中的值的反应条形图,r,shiny,shinydashboard,R,Shiny,Shinydashboard,根据我的数据,我可以准备一个简单的道奇条形图 geo <- data.frame("year" = c(2018, 2018, 2018, 2019, 2019, 2019, 2020, 2020, 2020), "geo" = c("Europe", "Asia", "America", "Europe", "Asia&
geo <- data.frame("year" = c(2018, 2018, 2018, 2019, 2019, 2019, 2020, 2020, 2020),
"geo" = c("Europe", "Asia", "America", "Europe", "Asia", "America", "Europe", "Asia", "America"),
"sales" = c(100, 150, 200, 500, 500, 500, 1200, 1800, 1200))
ggplot(geo, aes(fill=as.factor(year), x=geo, y=sales))+
geom_bar(position="dodge", stat = "identity")
geo可以这样实现:
您必须根据检查的年份筛选数据集。为此,请使用反应式
在renderPlot中,使用reactive返回的数据框进行绘图,只需在fill
图书馆(闪亮)
图书馆(shinydashboard)
地理位置
library(shiny)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody(
# Boxes need to be put in a row (or column)
fluidRow(
box(plotOutput("plot1", height = 250)),
box(
checkboxGroupInput("checkGroup", label = "Year",
choices = list("2018"=2018, "2019" = 2019, "2020" = 2020),
selected = 2018)
)
)
)
)
server <- function(input, output) {
output$plot1 <- renderPlot({
ggplot(geo, aes(fill=as.factor(input$checkGroup), x=geo, y=sales))+
geom_bar(position="dodge", stat = "identity")
})
}
shinyApp(ui, server)
library(shiny)
library(shinydashboard)
geo <- data.frame("year" = c(2018, 2018, 2018, 2019, 2019, 2019, 2020, 2020, 2020),
"geo" = c("Europe", "Asia", "America", "Europe", "Asia", "America", "Europe", "Asia", "America"),
"sales" = c(100, 150, 200, 500, 500, 500, 1200, 1800, 1200))
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody(
# Boxes need to be put in a row (or column)
fluidRow(
box(plotOutput("plot1", height = 250)),
box(
checkboxGroupInput("checkGroup", label = "Year",
choices = list("2018"=2018, "2019" = 2019, "2020" = 2020),
selected = 2018)
)
)
)
)
server <- function(input, output) {
dat <- reactive({
filter(geo, year %in% input$checkGroup)
})
output$plot1 <- renderPlot({
ggplot(dat(), aes(fill=as.factor(year), x=geo, y=sales))+
geom_bar(position="dodge", stat = "identity")
})
}
shinyApp(ui, server)