Dygraph和Graph在闪亮的选项卡下不显示。

问题描述 投票:0回答:1

我试图在r中创建一个闪亮的应用程序。然而,当我试图在相关的标签下绘制dygraph和最后一个图形时,它们不能像地图和第一个图形那样在标签面板上显示出来。我不明白为什么我已经尝试了许多事情来让它们显示。先谢谢你。

UI代码。

library(tidyverse)
library(shiny)
library(shinyWidgets)
library(shinythemes)
library(shinyBS)
library(shinydashboard)
library(xts)
library(dygraphs)
library(countrycode)
library(rworldmap)


ncov <- structure(list(Date = c("2020-05-07", "2020-05-07", "2020-05-07", 
                                "2020-05-07", "2020-05-07", "2020-05-07"), Country = c("Vietnam", 
                                                                                       "West Bank and Gaza", "Western Sahara", "Yemen", "Zambia", "Zimbabwe"
                                ), Confirmed = c(288L, 375L, 6L, 25L, 153L, 34L), Recovered = c(233L, 
                                                                                                176L, 5L, 1L, 103L, 5L), Deaths = c(0L, 2L, 0L, 5L, 4L, 4L)), row.names = 20004:20009, class = "data.frame")




ui <- fluidPage(

  #being able to select the country and get an individual graph
  titlePanel("Corona Virus"),
  sidebarLayout(

    sidebarPanel(

      selectInput(
        inputId = "Country",
        label = "Country",
        choices = ncov$Country
      ), 

    ),
    dashboardPage(skin = "purple", 
                  #title of the dashboard
                  dashboardHeader(title = "CoronaVirus"), 


                  dashboardSidebar(width = 250,
                                   sidebarMenu(
                                     id = "sidebarmenu",
                                     menuItem("Main", tabName = "Main"),
                                     menuItem("Map", tabName = "Map"),
                                     menuItem("Other Diseases", tabName = "Other Diseases"),
                                     menuItem("Whole World", tabName = "Whole World")



                                     #dashboard body                                 
                                   )),
                  dashboardBody(

                    tags$head
                    (
                      tags$link(rel = "stylesheet", type = "text/css", href = "custom3.css")
                    ),

                    #confirmed number of cases
                    bsPopover (id = "q1", title = "Confirmed",
                               trigger = "hover",
                               placement = "top",
                               options = list(container="body")),

                    #recovered number of cases
                    bsPopover (id = "q1", title = "Recovered",
                               trigger = "hover",
                               placement = "top",
                               options = list(container="body")),

                    #Dead number of cases
                    bsPopover (id = "q1", title = "Dead",
                               trigger = "hover",
                               placement = "top",
                               options = list(container="body")),

                    tabItems(

                      tabItem(tabName = "Main",
                              fluidRow(
                                infoBoxOutput("info1"), width=10,
                                infoBoxOutput("info2"), width=10,
                                infoBoxOutput("info3"), width=10),
                              #dygraph of the whole world

                              plotOutput("plot"),

                              mainPanel(

                              )),#end main Panel

                      tabItem(tabName = "Map",
                              plotOutput("map"),
                              mainPanel()),
                      tabItem(tabName = "Other Diseases",
                              plotOutput("plott"),
                              mainPanel()),
                      tabItem(tabName = "Whole World",
                              plotOutput("plott"),
                              mainPanel())
                    )#end tab Items



                  )#end dashboard body
    )#end dashboard
  )#end side bar layout``
)
# Define server logic required to draw a histogram
server <- function(input, output) {

  output$plot <- renderPlot({
    data <- ncov %>% dplyr::filter(Country == input$Country)
    ggplot(data, aes(y = Deaths, x = Confirmed)) + geom_point()
  })

  output$plott <- renderPlot({
    data <- ncov 
    ggplot(data, aes(y = Deaths, x = Confirmed)) + geom_point()
  })



  #info box 1
  output$info1 <- renderInfoBox({
    infoBox("Confirmed",sum(ncov$Confirmed,na.rm = TRUE),
            fill = TRUE, color = "yellow", icon("arrow-up"))})

  #info box 2
  output$info2 <- renderInfoBox({
    infoBox("Recovered",sum(ncov$Recovered,na.rm = TRUE),
            fill = TRUE, color = "green", icon("arrow-up"))})

  #info box 3S
  output$info3 <- renderInfoBox({
    infoBox("Dead",sum(ncov$Deaths,na.rm = TRUE),
            fill = TRUE, color = "red", icon("arrow-up"))})

  output$map <- renderPlot({
    #map

    ans <-ncov %>%
      filter(Date=="2020-05-06")%>%
      select("Confirmed")


    count<-countrycode(factor(ncov$Country), origin = 'country.name', destination = 'iso3c')
    # create data frame with iso3 country codes and number of visits
    countriesvisited <- data.frame(countries =count, conf = ans)



    # inspect data

    visitedMap <- joinCountryData2Map(countriesvisited, 
                                      joinCode = "ISO3",
                                      nameJoinColumn = "countries")

    # get map
    worldmap <- getMap(resolution = "coarse")
    # plot worldmap
    plot(worldmap, col = "lightgrey", 
         fill = T, border = "darkgray",
         xlim = c(-180, 180), ylim = c(-90, 90),
         bg = "aliceblue",
         asp = 1, wrap=c(-180,180))
    # def. map parameters, e.g. def. colors
    temp <-mapCountryData(visitedMap, 
                          nameColumnToPlot="Confirmed",
                          oceanCol = "azure2",
                          catMethod = "categorical",
                          missingCountryCol = gray(.8),
                          colourPalette = heat.colors(171),
                          addLegend = F,
                          mapTitle = "",
                          border = NA)

    do.call(addMapLegendBoxes, c(temp,
                                 x = "left",
                                 title = "Corona Cases for the previous day",
                                 horiz = FALSE,
                                 bg = "transparent",
                                 bty = "n"))

  })

}#end server

# Run the application 
shinyApp(ui, server)
r graph shiny dygraphs
1个回答
0
投票

标签不喜欢标签名中的空格。只要我把空格去掉,就开始工作了。

© www.soinside.com 2019 - 2024. All rights reserved.