Request for Expert Assistance on How to Inserting Data in to the Database(SQLite) Using Shiny for Python

I hereby request for a help on the app I am developing using Shiny for Python, I got stuck and I search ChatGPT and Bard AI I could not get the procedure of how to insert my data in the database using SQL statements; colleagues see the code below for the shiny app for python for your perusal
Many thanks for the support

import sqlite3
import re
from datetime import date
from pathlib import Path
from htmltools import div, tags, TagList
from shiny import *
from shinywidgets import output_widget, register_widget, render_widget

current_dir = Path(__file__).parent if "__file__" in locals() else Path.cwd()
database_path = current_dir / "student.db"

# Create a database connection
conn = sqlite3.connect('student.db')
c = conn.cursor()

# Drop the existing table
c.execute('''DROP TABLE IF EXISTS std''')

# Create a new table to store patient information
c.execute('''CREATE TABLE std
              name TEXT,
              age INTEGER,
              gender TEXT,
              date DATE)''')

#----------------------------Shiny UI------------------------------------------
app_ui = ui.page_fluid(
    ui.input_text("name", "Name"),
    ui.input_numeric("age", "Age", value=0),
                choices=["Male", "Female"],),
    ui.input_date("date", "Date Enroll"),
    ui.input_action_button("submit", "Sumbit"),
            'width: 45%;'
            "display: flex;"
            'padding: 40px 10px;'
            'margin: 8px 2;'
            'display: inline-block;'
            'border: 1px solid #ccc;'
            'border-radius: 4px;'
            'box-sizing: border-box;'
            'border-radius: 30px;'
            'background-color: #f69471;'
            "gap: 0.6em;"
            'transition: width 0.4s ease-in-out;'
#------------------------server logic----------------------------------
def server(input, output, session):
    def _():
        cur = conn.cursor()
        cur.execute('''INSERT INTO std (name, age, gender, date)
                 VALUES (?, ?, ?, ?)''',
app = App(app_ui, server)

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