r - R shinyApp 应用程序有效,但在我的 . 需要简化
问题描述
此处提供完整代码:https://github.com/donwillmar/dataviz/blob/master/Evomass_RUG(app.R)
我做了一个函数shinyApp
,可以比较一个数据集中的 3 个指标在橄榄球队中的位置。
在数据集中,观察结果如下所示:
| Year | Name | Nation | Zone | KG | CM | BMI |
| 2019 | Bob | USA | Flyhalf | 80 | 183 | 23 |
有 7 个不同的职位~Zone
,我在各个指标KG
中分别CM
进行了比较。总共有 111 个地块,我将它们保存为一个名为“地块”的列表。BMI
ggplots
ui <- fluidPage(
theme = shinythemes::shinytheme("superhero"),
titlePanel("Mass Evolution of Rugby Internationals"),
sidebarPanel(position = "left",
wellPanel(h3("Variables"),
radioButtons(inputId = "yvar", label = h4("Mass Metric"),
choices = list("Body Mass Index" = "BMI", "Weight (KG)" = "KG","Height (CM)" = "CM"),
selected = "BMI"),
selectInput(inputId = "zone", label = h4("Position Zone"),
choices = list("Front Row", "Second Row", "Back Row",
"Scrumhalf", "Flyhalf", "Centre", "Outside Back"),
selected = "Front Row"),
selectInput(inputId = "comp", label = h4("Compare Position"),
choices = list("None", "Front Row", "Second Row", "Back Row",
"Scrumhalf", "Flyhalf", "Centre", "Outside Back"),
selected = "None")
在函数中server.R
,我根据用户的if
和else
ggplot
plots
input$zone
input$compare
server <- function(input, output) {
selectedData <- reactive({
c(input$yvar, input$zone, input$comp)
})
output$graf <- renderPlot ({
if ((input$yvar == "BMI") & (input$zone == "Front Row") & (input$comp == "None")){
plots[[1]]
} else if ((input$yvar == "BMI") & (input$zone == "Front Row") & (input$comp == "Front Row")){
plots[[1]]
} else if ((input$yvar == "BMI") & (input$zone == "Front Row") & (input$comp == "Second Row")) {
plots[[28]]
} else if ((input$yvar == "BMI") & (input$zone == "Front Row") & (input$comp == "Back Row")) {
plots[[29]]
...这些陈述中有 111 条。
我对这个应用程序失去了动力,因为我想向它添加更多内容,而且我知道有一种更简单的方法可以将它与switch
功能或其他东西一起使用,但我似乎无法弄清楚。
解决方案
推荐阅读
- php - PHP BBCODE 解析器 XSS
- java - 如何将对象存储在 ArrayList 中并打印出来?
- kotlin - 迁移到非实验性协程
- apache - 如何使用单个 RewriteRule 通过 .htaccess 将所有内容重定向到 https 和非 www?
- unity3d - 使用 Camera.main.ScreenToWorldPoint 时出现对象引用错误
- javascript - 将最大高度设置为已经响应的 D3 圆环图
- ruby-on-rails - 如何访问 Rails API 中的请求标头?
- html - 下拉框没有响应
- css - LESS - 在父级上使用带有额外类的 BEM 选择器来偏离
- python - fixed-size topics vector in gensim LDA topic modelling for finding similar texts