Python in shiny app

Hi team,

I am new to Rstudio and Shiny. I am in need of running python code when we click a button in UI I created in shiny app. Is it possible to do this?
Attaching the code of UI.

ui <- fluidPage(
titlePanel("R Session Cleaner"),
label = "Choose",
radioButtons("radio", label = h3("Radio buttons"),
choices = list("Test1" = 1, "Test2" = 2,
"Test3" = 3),
selected = 1),

fluidRow(column(3, verbatimTextOutput("value")))

server <- function(input, output) {
output$value <- renderPrint({ input$radio })
shinyApp(ui, server)
Thanks in advance,


You can source python functions and use it as any other function in R by using the reticulate package, but you can't directly use python syntax on a shiny app.

@andresrcs So how can I import the python code in shiny app when I click a button? Do you guys have an example to post? Or can you edit my code and add like dumb python code and post it?

Using a command like this `reticulate::source_python("")

But sourcing your python code each time you press a button doesn't sound like a good idea, it would be better to source your python function at session level and then use that function in your button as it was regular R code.

If you need more specific help please provide a minimal reproducible example (reprex) illustrating your issue. Have a look at this guide, to see how to create one for a shiny app

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