Question: Using Python and Mongo DB with Dash Framework: I am trying to print my query onto this HTML web application but I can not seem
Using Python and Mongo DB with Dash Framework:
I am trying to print my query onto this HTML web application but I can not seem to get the query results to print. The Animal Shelter Class that is being used is working fine with just a regular python script, so I don't think it is that. Any ideas on how to get the query to pint would be greatly appreciated.
Here is my code:
from jupyter_plotly_dash import JupyterDash import dash_core_components as dcc import dash_html_components as html import dash from dash.dependencies import Input, Output from pymongo import MongoClient import urllib.parse from bson.json_util import dumps from AAC import AnimalShelter #TODO: import for their CRUD module
# this is a juypter dash application app = JupyterDash('ModuleFive')
# the application interfaces are declared here # this application has two input boxes, a submit button, a horizontal line and div for output app.layout = html.Div( [ dcc.Input( id="input_user".format("text"), type="text", placeholder="input type {}".format("text")), dcc.Input( id="input_passwd".format("password"), type="password", placeholder="input type {}".format("password")), html.Button('Execute', id='submit-val', n_clicks=0), html.Hr(), html.Div(id="query-out"), html.H6('Jacqueline Woods') ])
# this is area to define application responses or callback routines # this one callback will take the entered text and if the submit button is clicked then call the # mongo database with the find_one query and return the result to the output div @app.callback( Output("query-out", "children"), [Input("input_user".format("text"), "value"), Input("input_passwd".format("password"),"value"), Input('submit-val', 'n_clicks')], [dash.dependencies.State('input_passwd', 'value')] ) def cb_render(userValue,passValue,n_clicks,buttonValue): if n_clicks > 0: ########################### # Data Manipulation / Model # use CRUD module to access MongoDB ########################## username = urllib.parse.quote_plus(userValue) password = urllib.parse.quote_plus(passValue) #TODO: Instantiate CRUD object with above authentication username and password values dataObj= AnimalShelter() dataObj._init_(username, password) # creates instance of animal shelter class and enters the AAC database query = dumps(dataObj.read({"animal_type": "Dog","name":"Lucy"})) html.H1(query) ########this is what I am trying to get to appear on the html doc # note that MongoDB returns BSON, the pyMongo JSON utility function dumps is used to convert to text #TODO: Return example query results
app
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
