我希望这段代码能够返回pass的值,但事实并非如此。代码在哪里不正确?这是Shiny应用程序的一部分。它在ui函数外部和服务器函数外部具有ui <- fluidPage()
函数,server()
函数和helper
函数。可以完成以下任务吗?
在ui <- fluidPage()
功能中,要求用户上传文件。我需要提取filename
,因此在server
函数中,observeEvent
中的参数为input$file
,而fileName
为input$file$name
。
我从helper
函数调用server
函数。 helper
函数是glycoPipe&lt; - function(fileName)and pass
输入$ file $ name`。
glycoPipe <- function(fileName)
接收参数并调用另一个函数(pass = checkParams(fileName)) which accepts the
fileName`参数。
function2(fileName)
在脚本"utilities.R"
中定义。此函数处理文件并返回变量pass中的值。
source("utilityFunctions/utilities.R")
#checkParams<- function(fileName){pass = TRUE} is in utilities.R
ui <- fluidPage(
fluidRow(
column(width = 10,
conditionalPanel(
condition = "input.btn == true",
selectInput("value", label = h4("Do you have a params file ready to use (Y/N)?"),
choices = c("", "Y", "N"), selected = NULL)
),
conditionalPanel(
condition = "input.value == 'Y'",
helpText(h4("Select your params file")),
fluidRow(
column(width = 10, fileInput("file", "upload the file", accept = ".tsv", placeholder = "No file selected", multiple = FALSE))
)
)
)
)
)
#helper function
glycoPipe <- function(filename = NULL){
pass <- reckParams(filename)
list(pass = pass)
}
server <- function(input, output, session){
observeEvent(input$value,{
fileName = input$file$name
result <- function1(function2(fileName))
value = result$pass
output$textbox <- renderText({
paste("Your result is", value)
})
})
}
utilities.R contains
checkParams <- function{
pass = TRUE,
pass}
如果我不采购,我会得到正确的结果:
glycoPipe <- function(PARAMSfullFile=NULL){
list(pass = pass)
pass<- checkParams(PARAMSfullFile)
if (!pass) return()
}
checkParams <- function(PARAMSfullFile = NULL){
pass = TRUE
}
server <- function(input, output, session){
observeEvent(input$value,{
result <- glycoPipe(checkParams(input$file$name))
value = result$pass
output$box <- renderText({
paste("Your result is", value)
})
})
}