【问题标题】:Passing the value of input$variable as an argument in Rshiny to external script call将 input$variable 的值作为 R Shiny 中的参数传递给外部脚本调用
【发布时间】:2018-05-14 11:46:56
【问题描述】:

正在使用的 R 闪亮代码是:

library(shiny)
library(shinyBS)
ui <-  fluidPage(
  headerPanel( list(tags$head(tags$style("body {background-color: #F4F6F6 ; }")))),
  titlePanel("RADP CR Prediction Tool"),
  br(),
  tags$head(tags$script(src = "message-handler.js")),
  textInput('Region', label = 'Enter the region'),
  textInput('Regulatory', label = 'Enter the regulatory status'),
  textInput('Description', label = 'Enter the description for the CR'),
  br(),
  br(),
  actionButton("goButton", "Go!"),
  mainPanel(textOutput('region'),textOutput('description')),
  bsModal("modalExample", "Your summary", "goButton", size = "large",dataTableOutput("data_summary"))
     )

server <- function(input,output,session) {
  #observe the add click and perform a reactive expression
  observeEvent( input$goButton,{
    x <- input$Region
    y <- input$Regulatory
    z<- input$Description
    print (x)
    system("/Users/ravinderbhatia/anaconda/bin/python /Users/ravinderbhatia/Downloads/Untitled3.py input[[x]] ,'y', 'z'")
    MyData <- read.csv(file="/Users/ravinderbhatia/Downloads/data.csv", header=TRUE)
    #reactive expression
    output$region <- renderPrint(x)
    output$description <-renderPrint(y)
    output$data_summary <- renderDataTable({
      MyData
    })
  }
  )
}

shinyApp(ui, server)

问题如下:

 system("/Users/ravinderbhatia/anaconda/bin/python /Users/ravinderbhatia/Downloads/Untitled3.py x,y,z")

如何在系统调用中传递region的实际值。这里 print(x) 工作正常,但是当我将 x 作为参数传递时,我想传递存储在其中的值。(input$region)

【问题讨论】:

    标签: python r shiny


    【解决方案1】:

    好吧,你只是将一个字符 x 传递给系统,它可能不知道如何处理它。

    如果你改变这一行会怎样:

    system("/Users/ravinderbhatia/anaconda/bin/python /Users/ravinderbhatia/Downloads/Untitled3.py input[[x]] ,'y', 'z'")
    

    到:

    system(paste("/Users/ravinderbhatia/anaconda/bin/python /Users/ravinderbhatia/Downloads/Untitled3.py", x, y, z))
    

    试试那几行,我用“print”替换了“system”

    x= "desc"
    y= "region"
    z= "etc"
    print("/Users/ravinderbhatia/anaconda/bin/python /Users/ravinderbhatia/Downloads/Untitled3.py input[[x]] ,'y', 'z'")
    print(paste("/Users/ravinderbhatia/anaconda/bin/python /Users/ravinderbhatia/Downloads/Untitled3.py", x, y, z))
    

    【讨论】:

    • 我已经尝试过传递 x、y、z。那是行不通的。 Python 将其 x 作为参数,而不是其中的值。
    • 如果将命令保存在变量中并将其传递给 system() 会怎样。喜欢:a
    • 没有成功。它仍然只读取 x,y,z。也不确定 x、y 和 z 之间的昏迷。
    • 我尝试创建一个可重现的示例,它对我有用。它采用分配给 x,y,z 的值。我只是将系统命令的第一部分更改为 python.exe 的完整路径。 (system(paste("C:/Anaconda/python.exe C:/py_function.py", x, y, z))),因为您只指向python而不是可执行文件?
    • 我在 Mac 上。没有可执行文件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多