Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用过滤器时未达到预期效果_R_Shiny_Shinyapps - Fatal编程技术网

R 使用过滤器时未达到预期效果

R 使用过滤器时未达到预期效果,r,shiny,shinyapps,R,Shiny,Shinyapps,对于R或任何编程来说还是非常陌生的,向部门展示一些健康结果数据,我想我会尝试写一些东西,让我选择要显示的数据子集。完成了一些自主阅读,并尝试了以下内容(请参见下文)。 我的问题是,当我选择全部4种“手术方法”时,我得到的结果并不是我所期望的。例如,2019年7月的平均服务水平应低于我在这里看到的水平 正如我所说,这是一个非常新的问题,请假设我在回答这个问题时一无所知 # User Interface ui <-basicPage( sliderInput("year", "Selec

对于R或任何编程来说还是非常陌生的,向部门展示一些健康结果数据,我想我会尝试写一些东西,让我选择要显示的数据子集。完成了一些自主阅读,并尝试了以下内容(请参见下文)。
我的问题是,当我选择全部4种“手术方法”时,我得到的结果并不是我所期望的。例如,2019年7月的平均服务水平应低于我在这里看到的水平

正如我所说,这是一个非常新的问题,请假设我在回答这个问题时一无所知

# User Interface

ui <-basicPage(
  sliderInput("year", "Select Year:", animate = T,
              min = 2016, max = 2019, value = 2016, sep = ""),

  checkboxGroupInput("approach", "Surgical Approach", c("Laparoscopic", "Lap-assisted", "Converted to open", "Open"),
                     selected = c("Laparoscopic", "Lap-assisted", "Converted to open", "Open")),

plotOutput(outputId = "LOS_plot"),

  plotOutput(outputId = "All3_plot")
)

# Server

server <- function(input, output){

  output$LOS_plot <- renderPlot({

    ERAS %>% filter(Sx_Approach == input$approach) %>% 
      arrange(year_m) %>% 
      mutate(DoSdate = ymd(year_m), yearDoS = year(DoSdate), monthDoS = month(DoSdate)) %>% 
      filter(yearDoS == input$year) %>%
      group_by(year_m) %>% mutate(mean_LOS = mean(Postop_LOS)) %>%
      ggplot(aes(x = monthDoS, y = mean_LOS)) + geom_line(colour = "black", size = 1.5) +
      scale_x_continuous(limits = c(1, 12), breaks = c(1:12)) +
      scale_y_continuous(limits = c(0, 30), minor_breaks = 1) +
      theme(aspect.ratio = 0.4) + xlab("Month") + ylab("Days") + ggtitle("Mean Length of Stay over Time")

  })
  output$All3_plot <- renderPlot({

    ERAS %>% filter(Sx_Approach == input$approach) %>%
      arrange(year_m) %>% 
      mutate(DoSdate = ymd(year_m), yearDoS = year(DoSdate), monthDoS = month(DoSdate)) %>% 
      filter(yearDoS == input$year) %>%
      group_by(year_m) %>% mutate(mean_All3 = mean(All_3 == T, na.rm = T)) %>%
      ggplot(aes(x = monthDoS, y = mean_All3)) + geom_line(colour = "#5391c6", size = 1.5) + scale_x_continuous(limits = c(1, 12), breaks = c(1:12)) +
      scale_y_continuous(labels = scales::percent, limits = c(0, 1)) +
      theme(aspect.ratio = 0.4) + xlab("Month") + ylab("Percentage") + ggtitle("Patients Achieving All Three ERAS Goals")

  })
}

#用户界面
ui%
突变(DoSdate=ymd(year_m),yearDoS=year(DoSdate),monthDoS=month(DoSdate))%>%
过滤器(yearDoS==输入$year)%>%
按年份分组%>%变异(平均服务水平=平均服务水平(术后服务水平))%>%
ggplot(aes(x=月,y=平均服务水平))+geom线(color=“black”,size=1.5)+
比例x连续(极限=c(1,12),断裂=c(1:12))+
刻度连续(限值=c(0,30),小断开=1)+
主题(纵横比=0.4)+xlab(“月”)+ylab(“日”)+ggtitle(“平均停留时间”)
})
输出$All3_绘图%过滤器(Sx_方法==输入$Approach)%>%
安排(年)%>%
突变(DoSdate=ymd(year_m),yearDoS=year(DoSdate),monthDoS=month(DoSdate))%>%
过滤器(yearDoS==输入$year)%>%
按(年份)分组%>%突变(平均值3=平均值(所有值3==T,na.rm=T))%>%
ggplot(aes(x=monthDoS,y=mean_All3))+geom_线(color=“#5391c6”,size=1.5)+比例连续(极限=c(1,12),断裂=c(1:12))+
比例y连续(标签=比例::百分比,限值=c(0,1))+
主题(纵横比=0.4)+xlab(“月”)+ylab(“百分比”)+ggtitle(“患者实现所有三个ERA目标”)
})
}

不要使用“过滤器”,尝试使用“子集”使用sliderInput和checkboxGroupInput仅选择数据框的一部分。在不知道您正在使用的数据结构的情况下,它看起来是这样的:

ERAS <-  subset(Sx_Approach, (year==input$year & approach==input$approach))

ERAS感谢您的支持。发布问题后,我对代码进行了反复研究,发现使用
filter(Sx\u方法==input$Approach)
而不是
filter(Sx\u方法%在%input$Approach中)
似乎也起到了作用。不过我会试试你的答案。非常感谢