将input $ variable的值作为Rshiny中的参数传递给外部脚本调用

时间:2018-05-14 11:46:57

标签: python r shiny

使用的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作为参数传递时,我想传递存储在其中的值。(输入$ region)

1 个答案:

答案 0 :(得分: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))