(R / SHINY) - 使用selectInput选择(哪个)要显示的无效表

时间:2018-04-27 00:43:46

标签: r shiny

所以我脑子里有一个简单的问题。

  1. 我有一个selectInput。我们称之为report_select,其中包含“报告1”和“报告2”选项供您选择。

  2. 另外,我有一个textInput(用于指定员工ID)

  3. 我有两个被动反应(让我们称之为r_one和r_two)。这些导致基于员工的单独数据。

  4. 我有一个输出$ table1

  5. 目标:我希望下拉菜单控制两个被动报告的WHICH显示在表1中。

    注1:表格单独工作正常。我可以一个接一个地显示没有问题。 注2:我正在使用SHINY以及用于组织的tabsetpanel和tabpanel

    有哪些方法可以帮助解决这个问题?

    方法1 :(错误是“不允许从shionyoutput对象读取对象”

    library(shiny)
    library(readxl)
    library(dplyr)
    library(tidyr)
    
    # Globally Pull In Files
    new_compdump_data <- read_xlsx("C:/temp/FILE.xlsx")
    
    #Format Imported Data
    clean_new <- subset(new_compdump_data,is.na(new_compdump_data$Term_Date))
    clean_new$AIN <- as.numeric(clean_new$AIN)
    clean_new$`MIP value` <- clean_new$`MIP%`*clean_new$Salary
    # Begin UI
    ui <- fluidPage(
    titlePanel("Data Tool"),
    
    sidebarLayout(
    sidebarPanel(
      selectInput(inputId = "report_select",
                  label = "Select a Report",
                  choices = c("Base Info","Stock Info")),
      textInput("stock_ain","AIN")
    ),  #End SideBarPanel             
    
    mainPanel(
      tabsetPanel(
        tabPanel(title="Base Info",tableOutput("table1")
      )))
    ))
    
    #======= SHINY - Server Section
    
    server <- function(input, output) {
    
    report1 <- reactive({
    subset(clean_new[c(5,1,2,3)],clean_new$AIN==input$AIN)
    })
    
    report2 <- reactive({
    subset(clean_new[c(5,6,7,8)],clean_new$AIN==input$AIN)
    })
    
    report_choose <- reactive({
    ifelse(input$report_select=="Base Info",report1(),
    ifelse(input$report_select=="Stock Info",report2()))
    })
    
    output$table1({
    report_choose()
    })
    
    } #End server info
    
    # Run the App
    shinyApp(ui = ui, server = server)
    

    方法2:错误:与上面相同

    与上述相同,但对report_choose的反应是:

    report_choose <- reactive{(
    switch(input$report_select,
    "Base Info"=report1(),
    "Stock Info"=report2())
    )}
    

    方法3 :(错误是“不允许从shionyoutput对象读取对象”

    与上述相同(部分)但

    report_choose <- reactive({
    if(input$report_select=="Base Info") {
    report1()
    } else {
    report2()
    }
    })
    

    仍然没有骰子。任何想法或方法?

0 个答案:

没有答案
相关问题