首页 > 解决方案 > 如何将 covid19.analytics 中的 live.map 功能添加到闪亮的应用程序中?

问题描述

我正在尝试创建一个 covid19 交互式信息应用程序,但将 covid19.analytics 包中的 live.map() 添加到我的应用程序时遇到了很多麻烦

   library(shiny)
    library(shinythemes)
    library(covid19.analytics)
    library(plotly)

    ui <- fluidPage(theme=shinytheme("cosmo"), 
            navbarPage( "COVID 19 APPLICATION",
              tabPanel(
                "Interactive COVID 19 MAP",
                  sidebarPanel(
                      
                    ),
                       mainPanel(
                  plotlyOutput("map")
                  )
                ), tabPanel(
                  "Countries",
                  sidebarPanel(
                    selectInput(inputId = "countries", label = "country selection", choices = c("country 1", "country 2", "country 3")), 
                      
                    ),
                 mainPanel(
                    plotOutput( outputId = "countries") 
                  )     
                  ),
                
                 tabPanel(
                  "coolness XD",
                  sidebarPanel( ),
                    
                mainPanel(
                    plotOutput( outputId = "coolness") 
                  )  
                 
                )
            
                ),
              ) 

    server <- function(input,output){
  

    output$map <- renderPlotly({
    x <- live.map()
    output$map <- x
  })
 
}


shinyApp(ui=ui,server=server)


output$map <- renderPlotly({
    x <- live.map()
    output$map <- x
  })
 
}


shinyApp(ui=ui,server=server)
        
          
            

我仍然是闪亮的初学者,所以使用 renderplot/renderplotly 函数有点令人困惑。有谁知道我该如何解决这个问题?

标签: rshinymapsplotlyinteractive

解决方案


您有几件事需要解决:

  1. 在 live.map fn 中你需要设置参数,interactive.display=FALSE否则live.map会启动它自己的 web 渲染

  2. 您的服务器部分需要修改如下,

    server <- function(input,output){
                output$map <- renderPlotly({
                x <- live.map(interactive.display=FALSE)
              })
    }

IE。您不需要从 renderPlotly 中将 x 重新分配给 output$map

Take a look also at some of the examples from the covid19.analytics dashboard explorer, https://github.com/mponce0/covid19.analytics/blob/master/R/covid19_dashboard.R

  1. Finally the last "orphan" output$map <- ... outside the server fn definition should be removed and only once instance of shinyApp(ui=ui,server=server) is needed.

推荐阅读