【问题标题】:Bar Plot does not Display in Shiny App, I have developed a code条形图在 Shiny App 中不显示,我开发了一个代码
【发布时间】:2021-01-31 01:53:59
【问题描述】:

我是闪亮应用程序的新手,正在尝试编写简单的代码。 我更改了很多次代码,但我的条形图不起作用。 我在其他尝试中遇到了这个问题。 UI 可以工作,服务器中的代码也可以在 R 中部分工作,但不能在闪亮的应用程序中工作。我知道我的服务器的某些部分不是我想要的,我只想知道我应该怎么做才能运行在 R 中有效但在 Shiny 中无效的代码

#Graph 2
server<-#Graph 2
library("tidyverse")
library("leaflet")
library("leaflet.extras")
library("rnaturalearthdata")
library("sf")
library("DT")
library("ggplot2")

N <- read.csv("https://data.ontario.ca/dataset/f4112442-bdc8-45d2-be3c-12efae72fb27/resource/455fd63b-603d-4608-8216-7d8647f43350/download/conposcovidloc.csv")


function(input, output, session){
 

  if(input$data.Gender){

     City ="Ottawa"
     
     N %>% subset(Reporting_PHU_City == City) %>%
       select(Case_Reported_Date, Age_Group, Client_Gender, Outcome1)%>%
       rename(Date = Case_Reported_Date)%>%
       arrange(Age_Group, Client_Gender, Outcome1)
     
     
     Data.N <- as.data.frame(N)
     Data.N %>%
       group_by(Age_Group) %>%
       summarise(Age = n_distinct(Age_Group)) %>%
       arrange(desc(Age))
     
     w = table(N$Age_Group)
     
     t = as.data.frame(w)

 }
 
 output$Plot <- renderPlot({

       ggplot() +
         geom_bar(stat = "identity",data = t,mapping = aes(x = N$Client_Gender , y =Freq))
   
 })

}

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    抱歉,该网站也不允许我共享 UI。这是Ui

    UI<- #Graph 2
    
    library("leaflet")
    library("DT")
    
    fluidPage(
      sidebarLayout(
        sidebarPanel(
          radioButtons("data.Gender", "",
                       c("Data female" = "Gender.Female",
                         "Data male" = "Gender.Male"))
        ),
    
      
    
        enter code here
          mainPanel(
            plotOutput("Plot")
          )
      ))
    

    【讨论】:

      【解决方案2】:

      也许您应该按Client_Gender 分组。您当前的Age_Group 分组将给出 1 作为所有组的值。

      试试这个

      server <- function(input, output, session){
      
       t <- reactive({
          input$data.Gender
         
          City ="Toronto"
      
          aa <- N %>% subset(Reporting_PHU_City == City) %>%
            select(Case_Reported_Date, Age_Group, Client_Gender, Outcome1)%>%
            rename(Date = Case_Reported_Date)%>%
            arrange(Age_Group, Client_Gender, Outcome1)
      
          bb <- aa %>%
            group_by(Client_Gender) %>%
            summarise(Age = n_distinct(Age_Group)) %>%
            arrange(desc(Age))
          
          bb
        })
       
      
        output$Plot <- renderPlot({
      
          ggplot(data=t()) +
            geom_bar(stat = "identity",mapping = aes(x = Client_Gender , y = Age))
      
        })
      
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-07-20
        • 2021-12-16
        • 1970-01-01
        • 1970-01-01
        • 2021-05-09
        • 2021-08-05
        • 2020-01-02
        相关资源
        最近更新 更多