我是新手shiny
并试图从用户选择的国家/stremgraph
地区制作一个闪亮的情节。selectInput
用户界面
library(shiny)
library(shinydashboard)
library(shinythemes)
library(shinyWidgets)
library(highcharter)
library(streamgraph)
tabPanel("Compare Countries",
# Application title
titlePanel("Select Countries to Compare"),
sidebarLayout(
sidebarPanel(width = 3,
selectInput(inputId = "id_compare_countries",
label = "Select Countries for comparison",
choices = unique(ts_all_long$Country.Region),
selected = c("United Kingdom","India","Spain","US","Russia","Canada","Germany"),
multiple = TRUE)
),
mainPanel(
# h2("~~~~~~~~~~WIP - Under Construction~~~~~~~~~~"),
streamgraphOutput("stream_cases"),
plotlyOutput("stream_cases2", height = "500px", width = "120%")
) # mainpanel end
) # sidebarLaout end
) # tabPanel end
服务器
library(shiny)
library(tidyverse)
library(tidytext)
library(scales)
library(lubridate)
library(glue)
library(ggtext)
library(highcharter)
library(plotly)
library(streamgraph)
library(shinyWidgets)
####################### tab 4 Plots ##############################
compare_daily_stacked_filtered <- reactive({
req(input$id_compare_countries)
compare_daily_stacked_filtered <- daily_stacked_df %>%
arrange(desc(date)) %>%
filter(Country.Region %in% input$id_compare_countries
)
}) %>%
bindCache(input$id_compare_countries)
# Streamgraph
output$stream_cases <- renderStreamgraph({
compare_daily_stacked_filtered() %>%
filter(
Daily_Cases_type %in% c("Confirmed_daily"),
Cases_count > 0,
) %>%
streamgraph(date = "date", value = "Cases_count", key = "Country.Region") %>%
sg_fill_tableau() %>%
sg_title(title = glue("Overal Countries Daily Cases trend Stream as of: {max(daily_stacked_df$date)}"))
})
# Cross check by Area graph in plotly
output$stream_cases2 <- renderPlotly({
ggplotly(ts_all_long %>%
filter(Country.Region %in% input$id_compare_countries
) %>%
ggplot(aes(x = date, y = Confirmed_daily, fill = Country.Region)) +
geom_area(alpha = 0.7) +
scale_fill_tableau() +
theme_transparent() +
theme(panel.grid.major = element_blank(),
panel.background = element_rect(fill = "transparent",colour = NA),
plot.background = element_rect(fill = "transparent",colour = NA),
legend.background = element_rect(fill = "transparent",colour = NA))
)
})
我试图与另一个正在显示但没有显示的区域图进行交叉检查。plotly
streamgraph