How to call Python function from R reticulate in Rmarkdown

I have this Rmarkdown, with a python function:

title: "An hybrid experiment"
    orientation: columns
    vertical_layout: fill
runtime: shiny

    ```{r setup, include=FALSE}

    def addTwo(number):
      return number + 2

And I try to use the function addTwo in a reactive context, so I tried this:

      the_number <- py$addTwo(input$selector)
      paste0("The text is: ",the_number)

But I got this error:

TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

Detailed traceback:
  File "<string>", line 2, in addTwo

I must be doing something wrong, please could you guide me to solve this problem?

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.