【问题标题】:Rshiny: How to create features based on value selected from UIR Shiny:如何根据从 UI 中选择的值创建功能
【发布时间】:2020-06-27 13:29:29
【问题描述】:

我是 rshiny 的新手 如何根据选择的值创建特征。 在数据中有交货日期,根据 UI 中的日期选择(“dateinput”)计算延迟天数,并为每个观察添加新功能,其值为“准时”、“延迟”或“未来”。

我是 rshiny 和 flexdashboard 的新手。

---
title: "Demo"
social: menu
runtime: shiny
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
    navbar:
      - {title: "<i class='fa fa-info'></i> Report Based on date 05-01-2019", align: right}
---

# Add Date Picker for Generate report Based on It.
dateInput("RDate",
  label = "Report Date",
  value = "2019-05-01",
  min = NULL,
  max = NULL,
  format = "yyyy-mm-dd",
  startview = "month",
  language = "en",
  width = NULL
  )



Raw_data_1 <-mutate(Raw_data_1, OT_Due_date = ifelse(Raw_data_1$DueDate >=  input$RDate,"Future",
                              (ifelse(is.na(Raw_data_1$LastRcvd),
                                      (ifelse((Raw_data_1$Received >=Raw_data_1$Ordered),"On Time","Late")),
                                                ifelse((Raw_data_1$Received >=Raw_data_1$Ordered) &
                                                (Raw_data_1$LastRcvd <= Raw_data_1$DueDate),"On Time","Late")))))

【问题讨论】:

    标签: r shiny shinydashboard flexdashboard


    【解决方案1】:

    我没有使用 flexdashboard 的经验,但是当您使用闪亮作为运行时时,您必须以不同的方式处理数据。 1) 所有被 input$ 值修改的数据必须在 Reactive 表达式中 2) 渲染必须由 renderTable/renderPlot 等专门调用

    这是最终为我工作的代码:

    ---
    title: "Demo"
    social: menu
    runtime: shiny
    output: 
      flexdashboard::flex_dashboard:
        orientation: rows
        vertical_layout: fill
        navbar:
          - {title: "<i class='fa fa-info'></i> Report Based on date 05-01-2019", align: right}
    ---
    
    ```{r global, include = FALSE}
    ### ADD HERE YOUR RAW DATA AND LIBRARIES
    ```
    
    # Add Date Picker for Generate report Based on It.
    
    ```{r}
    dateInput("RDate",
      label = "Report Date",
      value = "2019-05-01",
      min = NULL,
      max = NULL,
      format = "yyyy-mm-dd",
      startview = "month",
      language = "en",
      width = NULL
      )
    ```
    
    ```{r}
    Raw_data <- reactive({
      Raw_data_1 <- mutate(Raw_data_1, 
        OT_Due_date = ifelse(Raw_data_1$DueDate >= input$RDate,
                        "Future", 
                        ifelse(is.na(Raw_data_1$LastRcvd), 
                          ifelse((Raw_data_1$Received >= Raw_data_1$Ordered),
                            "On Time",
                            "Late"
                          ), 
                          ifelse(Raw_data_1$Received >= Raw_data_1$Ordered & 
                          Raw_data_1$LastRcvd <= Raw_data_1$DueDate,
                            "On Time",
                            "Late"
                          )
                        )
                      )
                    )
    })
    
    renderTable(Raw_data())
    ```{r}
    

    【讨论】:

      猜你喜欢
      • 2018-12-20
      • 2021-09-04
      • 2014-10-27
      • 2020-10-14
      • 1970-01-01
      • 2016-10-26
      • 1970-01-01
      • 1970-01-01
      • 2021-12-24
      相关资源
      最近更新 更多