Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 在Shiny中,提交按钮不是';t运行_R_User Interface_Shiny_Shiny Server_Shinyapps - Fatal编程技术网

R 在Shiny中,提交按钮不是';t运行

R 在Shiny中,提交按钮不是';t运行,r,user-interface,shiny,shiny-server,shinyapps,R,User Interface,Shiny,Shiny Server,Shinyapps,我编写了一个R脚本(MAIN.R),将PDF表格转换为CSV。当我将MAIN.R作为一个单独的文件运行时,它运行得很好。我已经试过很多次了 目前,我正在开发一个R闪亮应用程序,它使用“MAIN.R”作为源代码,并将pdf文件作为输入。当我按下提交按钮时,输出应该出现在主面板中。不幸的是,submit按钮没有按预期运行 谁能帮我一下吗,因为我是新来的 UI.R shinyUI(fluidPage( titlePanel("DATASET CONVERSION"),

我编写了一个R脚本(MAIN.R),将PDF表格转换为CSV。当我将MAIN.R作为一个单独的文件运行时,它运行得很好。我已经试过很多次了

目前,我正在开发一个R闪亮应用程序,它使用“MAIN.R”作为源代码,并将pdf文件作为输入。当我按下提交按钮时,输出应该出现在主面板中。不幸的是,submit按钮没有按预期运行

谁能帮我一下吗,因为我是新来的

UI.R

shinyUI(fluidPage(
  titlePanel("DATASET CONVERSION"),
  
  sidebarLayout(
    fileInput("filein", label = h2("Select a file to convert.")),
    submitButton("Submit")
  ),
  mainPanel(
    tableOutput("Dataset")
  )
)
)
source("MAIN.R")
shinyServer(function(input, output) {
  
  outputdf <-  reactive({ input$filein   
  })    
  output$Dataset <- renderTable({ 
    outputdf()
  })
})
Server.R

shinyUI(fluidPage(
  titlePanel("DATASET CONVERSION"),
  
  sidebarLayout(
    fileInput("filein", label = h2("Select a file to convert.")),
    submitButton("Submit")
  ),
  mainPanel(
    tableOutput("Dataset")
  )
)
)
source("MAIN.R")
shinyServer(function(input, output) {
  
  outputdf <-  reactive({ input$filein   
  })    
  output$Dataset <- renderTable({ 
    outputdf()
  })
})
source(“MAIN.R”)
shinyServer(功能(输入、输出){

outputdf您的Submit按钮当前未链接到任何内容,因此它不会执行任何操作。如果我正确阅读了代码,则您只需获取输入数据集并将其存储为outputdf的输出。然后,您的output$dataset只拾取该outputdf并按原样显示,而不需要对其进行任何操作

您使用的操作按钮如下所示:

## In UI.R
actionButton("execute", "Execute the Main Function")

## In Server.R
observeEvent(input$execute, {
    ## Do stuff here
  })
请注意,actionButton有两个参数,inputID(这是您对它的引用方式)和显示在顶部的文本。例如,对于input$filein,“filein”是inputID

在Server.R中,observeEvent在检测到输入$execute中的更改之前不会执行任何操作,这是在有人单击按钮时发生的。这就是您将代码用于执行操作的地方

现在,在output$Dataset中,您需要访问在该observeEvent中执行的任何操作的结果。一种方法是使用reactiveValue。这与reactiveValue类似,但它存储一个数据元素,而不是函数。将其初始化为空数据帧,然后在observeEvent中更新。类似于:

## In Server.R
treated_output <- reactiveValue(data.frame())

observeEvent(input$execute, {
    ## Run the function on the file
    updated <- main_function(input$filein)
    
    # Update your reactiveValue
    treated_output(updated)
  })

output$Dataset <- renderTable({ 
    treated_output()
  })
服务器.R中的
##

处理过的输出您可以包含
MAIN.R
文件来生成MRE吗?谢谢!如何定义
outputdf()
呢?我想在获取函数时出现了一些问题。另外请注意
submitButton
是@starja,它没有被弃用,它“通常不鼓励使用更通用的
actionButton()
”(尽管这种情绪仍然存在)。据我所知,
提交按钮是独立的,所有的反应在按下按钮之前都不会更新;但总的来说,你用
操作按钮的解决方案是更好的,很好,@Aqeel Padaria。非常感谢你。