Calling custom Python function in Shiny webapp
![info-rchitect](https://us.v-cdn.net/6038231/uploads/lithium_attachments/n9089iA7C08C68990A5113.png)
Hi,
I have a Shiny webapp that takes user inputs. I need to call a custom Python package function and pass the user inputs from the webapp and return the function value (in this case a SQL string) to the webapp. Then I need to run that SQL from the webapp and return the dataset for download to CSV.
thx
Operating system used: Windows 10
Best Answer
-
Alexandru Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 1,211 Dataiker
Hi @info-rchitect
,Using python code in rshiny app is possible with packages like: https://rstudio.github.io/reticulate/
Here is a sample
library(reticulate) use_python("/home/dataiku/dss_11/code-envs/python/py36test/bin/python") py_run_string(' import dataiku client = dataiku.api_client() def update_global_var(variable_name, variable_value): global_variables = client.get_variables() print(global_variables) global_variables[variable_name] = variable_value client.set_variables(global_variables) print(global_variables) ') main <- import_main() main$update_global_var(variable_name='some_variable', variable_value='some_value') py_capture_output(main$update_global_var(variable_name='some_variable', variable_value='some_value'))
Answers
-
AlexT,
Have you seen any performance, scalability issues when exchanging information between R Shiny and Python? The reason I ask is because, even though I love Python, DASH in Python is much more cumbersome and less elegant than Shiny IMO. However, R sucks for the dirty work under the hood. Hence, I hope this partnership will work well, if performance is not degraded too much.
thx