2

R shiny code being used is:

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)

Issue is in the follwing line:

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

How to pass the actual value of region in the system call. Here print(x) works fine, but when I pass x as a argument, I want to pass the value stored inside it.(input$region)

1 Answer 1

1

Well, like that you are just passing a character x to the system, and it probably has no idea what to do with that.

What if you changed this line:

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

to:

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

just try out those few lines, where i replaced "system" with "print"

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))
Sign up to request clarification or add additional context in comments.

6 Comments

I have already tried passing x, y, z. That does not work. Python takes its x as an argument, not the value in it.
What if you save the command in a variable and pass it then to system(). Like: a <- paste("/Users/ravinderbhatia/anaconda/bin/python /Users/ravinderbhatia/Downloads/Untitled3.py", x, y, z) system(a)
No success. Still it reads x,y,z only. Also not sure about the comas in between x,y and z.
I tried to create a reproducible example and it works for me. It takes the values, that are assigned to x,y,z. I just changed the first part of the system-command to the full path of the python.exe. (system(paste("C:/Anaconda/python.exe C:/py_function.py", x, y, z))), as you are only pointing to python and not an executable ?
I am on Mac. Do not have executable.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.