【问题标题】:how do you add the live.map function from covid19.analytics to a shiny app?如何将 covid19.analytics 中的 live.map 功能添加到闪亮的应用程序中?
【发布时间】:2021-03-17 04:50:21
【问题描述】:

我正在尝试创建一个 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)
        
          
            

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

【问题讨论】:

  • 好的,感谢您的建议,我仍然收到错误消息。 mapUnexpected htmlwidget output for map 的意外绘图输出我该如何解决?

标签: r shiny maps plotly interactive


【解决方案1】:

你有几件事需要解决:

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

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

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

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

还可以查看 covid19.analytics 仪表板资源管理器中的一些示例,https://github.com/mponce0/covid19.analytics/blob/master/R/covid19_dashboard.R

  1. 最后应该删除服务器 fn 定义之外的最后一个“孤儿”output$map &lt;- ...,并且只需要一次 shinyApp(ui=ui,server=server) 实例。

【讨论】:

    猜你喜欢
    • 2017-07-27
    • 2015-06-15
    • 2022-01-19
    • 2020-06-16
    • 1970-01-01
    • 2016-08-31
    • 1970-01-01
    • 2020-08-22
    • 1970-01-01
    相关资源
    最近更新 更多