Not able to print python function in R

I have declared a python function in R, but not able to call it in R. Not sure what wrong I am doing. Below is the reprex Can anyone help me here....................................

ui.R file

library(shiny)
library(shinydashboard)
library(reticulate)
source_python("python.py")

dashboardPage(  

  header <- dashboardHeader(disable = TRUE),

  dashboardSidebar(disable = TRUE),

  body <- dashboardBody(fluidRow(

          fluidRow(
          column(width = 12,actionButton("upload","Upload Text",width = 150)),
          column(width = 12,actionButton("clear_upload","Clear Output",width = 150))
        ),
        br(),
        verbatimTextOutput("code")
      )
      )
      )

server.R


server <- function(input, output,session) {
   get_code <- eventReactive(input$upload,{
      py$happyBirthday('Andre')
   })

   observeEvent(input$upload, {
      output$code <- renderPrint(get_code())
   })

   observeEvent(input$clear_upload, {
      output$code <- renderPrint("")
   })
}

python.R

def happyBirthday(person):
    print("Happy Birthday to you!")
    print("Happy Birthday to you!")
    print("Happy Birthday, dear " + person + ".")
    print("Happy Birthday to you!")

Hi Vinay,
I havent tried to run your code, nor have I ever used reticulate myself.
but in your UI I see

source_python("python.py")

and below you show a file that you called
python.R as containing your function.
Could it simply be a typo in your name ? .R vs .py ?

Hi,

Will try . Thanks...........

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.