闪亮的反应式汇总功能

时间:2019-05-07 13:19:42

标签: r shiny

在闪亮的应用程序中,给定输入,我必须定义不同的汇总公式。在这种情况下,输入为hp。问题在于,hp具有22个唯一值。我认为写22 if子句不是一个好主意。有其他选择吗?

output$stats <- renderTable({


if(input$hp == 52){
mtcars %>%
group_by_(input$cyl) %>%
summarize(formula0 = carb/100,
          formula1 = am*vs)

}

else if(input$hp == 62){
mtcars %>%
group_by_(input$cyl) %>%
summarize(formula2 = gear/carb,
          formula3 = am/vs) 

}
else if(input$hp == 65){

mtcars %>%
group_by_(input$cyl) %>%
summarize(formula4 = qsec + carb,
          formula5 = drat/disp) 

}
else
{

df_subset() %>%
group_by_(input$cyl) %>%
summarize(formula6 = mpg/10,
          formula7 = disp^2) ) 

}


})

0 个答案:

没有答案