如何使用反应函数输出的数据作为条件面板中的条件?

问题描述 投票:0回答:1

我正在尝试读取数据,如果数据有观察,则进一步的UI必须扩展。但

conditionalPanel
不起作用。

这是 UI 和服务器代码部分。

用户界面代码:


tabPanel("DMC 1.1", fluid = TRUE, useShinyjs(),
         column(width=12,wellPanel(div(style = 'height:120px;',
                              fluidRow(column(width=9,style = "font-size: 12px;",fileInput("analysis_data2", label = "Import data", accept = c(".csv",".sas7bdat",".xls",".xpt"))))
                              )),

 conditionalPanel(condition = "output.dataUpload",  wellPanel(fluidRow(

column(width=5,textInput("subset","Subsettign Condition",value="")),

column(width=5,textInput("byvar","By Variable",value="")),

column(width=5,textInput("subgrp","SubGroup Variable",value="")),

column(width=5,textInput("trtvar","Treatment Variable",value="")),

column(width=5,textInput("xaxisvar","X Axis Variable",value="")),

column(width=5,textInput("yaxisvar","Y Axis Variable",value=""))
                                               )))
                              )
                )


服务器代码:

  #################Tab 2 - DMC 2.0#########################
  

analysis_d <- reactive({data_read(datain=input$analysis_data2)})
  
output$dataUpload <- reactive({return(!is.null(isolate(analysis_d())))})
  
outputOptions(output, 'dataUpload', suspendWhenHidden=FALSE)
r shiny
1个回答
0
投票

如果上传的 csv 文件至少包含一行,此应用程序将在 UI 中提供额外的文本输入文件:

library(shiny)

ui <- fluidPage(
  fileInput("file", "File"),
  conditionalPanel(
    condition = "output.available",
    textInput("additional_input", "additional input")
  )
)

server <- function(input, output, session) {
  data <- reactive(read.csv(input$file$datapath))

  output$available <- reactive(nrow(data()) >= 1)
  outputOptions(output, "available", suspendWhenHidden = FALSE)
}

shinyApp(ui, server)
© www.soinside.com 2019 - 2024. All rights reserved.