微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法在 r 闪亮

如何解决无法在 r 闪亮

我是 shiny 的新手,并尝试在 stremgraph 中由 user 选择的 countries 制作一个闪亮的 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",legend.background = element_rect(fill = "transparent",colour = NA))
        )
    })

我试图与plotly中的另一个面积图进行交叉检查,该图显示只有streamgraph没有得到显示

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。