MySQL data source for shinyapps.io (python)

A python Shiny application accessing mysql data (external source) runs locally without any problem.

When publishing on shinyapps.io, the mysql module causes problems:

2024-09-17T08:28:46.748233+00:00 shinyapps[12541868]: Bootstrapping environment using Python 3.10.12 (main, May 7 2024, 12:36:30) [GCC 11.4.0] at /srv/connect/venv/bin/python
2024-09-17T08:28:46.751382+00:00 shinyapps[12541868]: Running content using the current Python environment
2024-09-17T08:28:47.811563+00:00 shinyapps[12541868]: Running content using Python “3.10.12 (main, May 7 2024, 12:36:30) [GCC 11.4.0]” at “/srv/connect/venv/bin/python”
2024-09-17T08:28:47.815216+00:00 shinyapps[12541868]: Loading code from “shiny.express.app:app_2e_py”
2024-09-17T08:28:49.730982+00:00 shinyapps[12541868]: Unexpected error while running Python API: No module named 'mysql'

Which module should be used to connect to mysql data source using python?

Hello,

Which library are you using for MySQL in Python? It seems there is a missing dependency ...

Grtz,
PJ

Hi,

I'm using the mysql library. Sample code:

from pathlib import Path
import mysql.connector

import pandas as pd

app_dir = Path(file).parent
#tips = pd.read_csv(app_dir / "tips.csv")

connection = mysql.connector.connect(
host="",
user="",
passwd="",
database=""
)

query = "SELECT * FROM tips"
tips = pd.read_sql(query, connection)

The problem has been solved.
The requirements.txt file must contain mysql-connector (and not mysql as I did by mistake).

This topic was automatically closed 7 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.