pythonherokuplotly-dashsensorsnidaqmx

Error when deployin a dash app to heroku, Nidaqmx.lib.DaqNotFoundError


I am trying to remotely read data from an accelerometer using a NI9234. I am working in windows, and I am usnig plotly dash and nidaqmx on python. The whole thing works fine on the local host (is able to fetch the data and it's plotting it), however, when I try to deploy it on Heroku, my accelerometer is not reading anything at all. I think that the deployment is working, but I have this as my log --tail:

2021-06-19T01:12:23.045293+00:00 heroku[router]: at=info method=GET path="/_dash-component-suites/dash_core_components/async-plotlyjs.v1_16_0m1617903285.js" host=monitoreo-remoto.herokuapp.com request_id=cc5a2471-0689-4b93-91cb-a0d0eb796e82 fwd="187.190.230.255" dyno=web.1 connect=0ms service=325ms status=200 bytes=1034463 protocol=https
2021-06-19T01:12:28.412217+00:00 app[web.1]: Exception on /_dash-update-component [POST]
2021-06-19T01:12:28.412225+00:00 app[web.1]: Traceback (most recent call last):
2021-06-19T01:12:28.412226+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 2070, in wsgi_app
2021-06-19T01:12:28.412227+00:00 app[web.1]: response = self.full_dispatch_request()
2021-06-19T01:12:28.412227+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 1515, in full_dispatch_request
2021-06-19T01:12:28.412228+00:00 app[web.1]: rv = self.handle_user_exception(e)
2021-06-19T01:12:28.412228+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 1513, in full_dispatch_request
2021-06-19T01:12:28.412228+00:00 app[web.1]: rv = self.dispatch_request()
2021-06-19T01:12:28.412229+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 1499, in dispatch_request
2021-06-19T01:12:28.412229+00:00 app[web.1]: return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
2021-06-19T01:12:28.412230+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/dash/dash.py", line 1079, in dispatch
2021-06-19T01:12:28.412230+00:00 app[web.1]: response.set_data(func(*args, outputs_list=outputs_list))
2021-06-19T01:12:28.412231+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/dash/dash.py", line 1010, in add_context
2021-06-19T01:12:28.412232+00:00 app[web.1]: output_value = func(*args, **kwargs)  # %% callback invoked %%
2021-06-19T01:12:28.412232+00:00 app[web.1]: File "/app/Vib-easy-3.py", line 110, in update_output
2021-06-19T01:12:28.412233+00:00 app[web.1]: with nidaqmx.Task() as task:
2021-06-19T01:12:28.412233+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/task.py", line 84, in __init__
2021-06-19T01:12:28.412233+00:00 app[web.1]: self._handle = lib_importer.task_handle(0)
2021-06-19T01:12:28.412234+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/_lib.py", line 178, in task_handle
2021-06-19T01:12:28.412234+00:00 app[web.1]: self._parse_typedefs()
2021-06-19T01:12:28.412235+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/_lib.py", line 241, in _parse_typedefs
2021-06-19T01:12:28.412235+00:00 app[web.1]: version = system.driver_version
2021-06-19T01:12:28.412236+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/system/system.py", line 73, in driver_version
2021-06-19T01:12:28.412236+00:00 app[web.1]: return DriverVersion(self._major_version, self._minor_version,
2021-06-19T01:12:28.412236+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/system/system.py", line 108, in _major_version
2021-06-19T01:12:28.412237+00:00 app[web.1]: cfunc = lib_importer.windll.DAQmxGetSysNIDAQMajorVersion
2021-06-19T01:12:28.412237+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/_lib.py", line 166, in windll
2021-06-19T01:12:28.412238+00:00 app[web.1]: self._import_lib()
2021-06-19T01:12:28.412244+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/_lib.py", line 218, in _import_lib
2021-06-19T01:12:28.412244+00:00 app[web.1]: raise DaqNotFoundError(
2021-06-19T01:12:28.412252+00:00 app[web.1]: nidaqmx._lib.DaqNotFoundError: Could not find an installation of NI-DAQmx. Please ensure that NI-DAQmx is installed on this machine or contact National Instruments for support.
2021-06-19T01:12:28.418592+00:00 app[web.1]: 10.16.188.22 - - [19/Jun/2021:01:12:28 +0000] "POST /_dash-update-component HTTP/1.1" 500 290 "https://monitoreo-remoto.herokuapp.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36"
2021-06-19T01:12:28.418956+00:00 heroku[router]: at=info method=POST path="/_dash-update-component" host=monitoreo-remoto.herokuapp.com request_id=fde7d56c-acbe-45f9-a1a6-54293cb22e55 fwd="187.190.230.255" dyno=web.1 connect=0ms service=181ms status=500 bytes=463 protocol=https
2021-06-19T01:12:44.515889+00:00 app[web.1]: Exception on /_dash-update-component [POST]
2021-06-19T01:12:44.515899+00:00 app[web.1]: Traceback (most recent call last):
2021-06-19T01:12:44.515900+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 2070, in wsgi_app
2021-06-19T01:12:44.515901+00:00 app[web.1]: response = self.full_dispatch_request()
2021-06-19T01:12:44.515901+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 1515, in full_dispatch_request
2021-06-19T01:12:44.515902+00:00 app[web.1]: rv = self.handle_user_exception(e)
2021-06-19T01:12:44.515902+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 1513, in full_dispatch_request
2021-06-19T01:12:44.515903+00:00 app[web.1]: rv = self.dispatch_request()
2021-06-19T01:12:44.515903+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 1499, in dispatch_request
2021-06-19T01:12:44.515904+00:00 app[web.1]: return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
2021-06-19T01:12:44.515904+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/dash/dash.py", line 1079, in dispatch
2021-06-19T01:12:44.515905+00:00 app[web.1]: response.set_data(func(*args, outputs_list=outputs_list))
2021-06-19T01:12:44.515905+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/dash/dash.py", line 1010, in add_context
2021-06-19T01:12:44.515906+00:00 app[web.1]: output_value = func(*args, **kwargs)  # %% callback invoked %%
2021-06-19T01:12:44.515906+00:00 app[web.1]: File "/app/Vib-easy-3.py", line 110, in update_output
2021-06-19T01:12:44.515906+00:00 app[web.1]: with nidaqmx.Task() as task:
2021-06-19T01:12:44.515907+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/task.py", line 84, in __init__
2021-06-19T01:12:44.515907+00:00 app[web.1]: self._handle = lib_importer.task_handle(0)
2021-06-19T01:12:44.515916+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/_lib.py", line 178, in task_handle
2021-06-19T01:12:44.515917+00:00 app[web.1]: self._parse_typedefs()
2021-06-19T01:12:44.515917+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/_lib.py", line 241, in _parse_typedefs
2021-06-19T01:12:44.515918+00:00 app[web.1]: version = system.driver_version
2021-06-19T01:12:44.515918+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/system/system.py", line 73, in driver_version
2021-06-19T01:12:44.515919+00:00 app[web.1]: return DriverVersion(self._major_version, self._minor_version,
2021-06-19T01:12:44.515919+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/system/system.py", line 108, in _major_version
2021-06-19T01:12:44.515919+00:00 app[web.1]: cfunc = lib_importer.windll.DAQmxGetSysNIDAQMajorVersion
2021-06-19T01:12:44.515920+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/_lib.py", line 166, in windll
2021-06-19T01:12:44.515920+00:00 app[web.1]: self._import_lib()
2021-06-19T01:12:44.515920+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/_lib.py", line 218, in _import_lib
2021-06-19T01:12:44.515920+00:00 app[web.1]: raise DaqNotFoundError(
2021-06-19T01:12:44.515921+00:00 app[web.1]: nidaqmx._lib.DaqNotFoundError: Could not find an installation of NI-DAQmx. Please ensure that NI-DAQmx is installed on this machine or contact National Instruments for support.
2021-06-19T01:12:44.530403+00:00 app[web.1]: 10.16.188.22 - - [19/Jun/2021:01:12:44 +0000] "POST /_dash-update-component HTTP/1.1" 500 290 "https://monitoreo-remoto.herokuapp.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36"
2021-06-19T01:12:44.531107+00:00 heroku[router]: at=info method=POST path="/_dash-update-component" host=monitoreo-remoto.herokuapp.com request_id=4cd69bda-50c6-4bd5-8a33-3cd423c725d1 fwd="187.190.230.255" dyno=web.1 connect=1ms service=179ms status=500 bytes=463 protocol=https
2021-06-19T01:12:48.609521+00:00 app[web.1]: Exception on /_dash-update-component [POST]
2021-06-19T01:12:48.609530+00:00 app[web.1]: Traceback (most recent call last):
2021-06-19T01:12:48.609531+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 2070, in wsgi_app
2021-06-19T01:12:48.609531+00:00 app[web.1]: response = self.full_dispatch_request()
2021-06-19T01:12:48.609532+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 1515, in full_dispatch_request
2021-06-19T01:12:48.609532+00:00 app[web.1]: rv = self.handle_user_exception(e)
2021-06-19T01:12:48.609533+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 1513, in full_dispatch_request
2021-06-19T01:12:48.609533+00:00 app[web.1]: rv = self.dispatch_request()
2021-06-19T01:12:48.609534+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 1499, in dispatch_request
2021-06-19T01:12:48.609534+00:00 app[web.1]: return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
2021-06-19T01:12:48.609534+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/dash/dash.py", line 1079, in dispatch
2021-06-19T01:12:48.609535+00:00 app[web.1]: response.set_data(func(*args, outputs_list=outputs_list))
2021-06-19T01:12:48.609535+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/dash/dash.py", line 1010, in add_context
2021-06-19T01:12:48.609536+00:00 app[web.1]: output_value = func(*args, **kwargs)  # %% callback invoked %%
2021-06-19T01:12:48.609536+00:00 app[web.1]: File "/app/Vib-easy-3.py", line 110, in update_output
2021-06-19T01:12:48.609537+00:00 app[web.1]: with nidaqmx.Task() as task:
2021-06-19T01:12:48.609537+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/task.py", line 84, in __init__
2021-06-19T01:12:48.609537+00:00 app[web.1]: self._handle = lib_importer.task_handle(0)
2021-06-19T01:12:48.609538+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/_lib.py", line 178, in task_handle
2021-06-19T01:12:48.609538+00:00 app[web.1]: self._parse_typedefs()
2021-06-19T01:12:48.609539+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/_lib.py", line 241, in _parse_typedefs
2021-06-19T01:12:48.609539+00:00 app[web.1]: version = system.driver_version
2021-06-19T01:12:48.609540+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/system/system.py", line 73, in driver_version
2021-06-19T01:12:48.609540+00:00 app[web.1]: return DriverVersion(self._major_version, self._minor_version,
2021-06-19T01:12:48.609540+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/system/system.py", line 108, in _major_version
2021-06-19T01:12:48.609541+00:00 app[web.1]: cfunc = lib_importer.windll.DAQmxGetSysNIDAQMajorVersion
2021-06-19T01:12:48.609541+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/_lib.py", line 166, in windll
2021-06-19T01:12:48.609542+00:00 app[web.1]: self._import_lib()
2021-06-19T01:12:48.609542+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/_lib.py", line 218, in _import_lib
2021-06-19T01:12:48.609542+00:00 app[web.1]: raise DaqNotFoundError(
2021-06-19T01:12:48.609543+00:00 app[web.1]: nidaqmx._lib.DaqNotFoundError: Could not find an installation of NI-DAQmx. Please ensure that NI-DAQmx is installed on this machine or contact National Instruments for support.
2021-06-19T01:12:48.612660+00:00 app[web.1]: 10.16.188.22 - - [19/Jun/2021:01:12:48 +0000] "POST /_dash-update-component HTTP/1.1" 500 290 "https://monitoreo-remoto.herokuapp.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36"
2021-06-19T01:12:48.613854+00:00 heroku[router]: at=info method=POST path="/_dash-update-component" host=monitoreo-remoto.herokuapp.com request_id=5a31bc51-2eef-4370-91bf-e91b144e2b37 fwd="187.190.230.255" dyno=web.1 connect=0ms service=185ms status=500 bytes=463 protocol=https
2021-06-19T01:15:31.312757+00:00 app[web.1]: Exception on /_dash-update-component [POST]
2021-06-19T01:15:31.312766+00:00 app[web.1]: Traceback (most recent call last):
2021-06-19T01:15:31.312770+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 2070, in wsgi_app
2021-06-19T01:15:31.312770+00:00 app[web.1]: response = self.full_dispatch_request()
2021-06-19T01:15:31.312771+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 1515, in full_dispatch_request
2021-06-19T01:15:31.312771+00:00 app[web.1]: rv = self.handle_user_exception(e)
2021-06-19T01:15:31.312771+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 1513, in full_dispatch_request
2021-06-19T01:15:31.312772+00:00 app[web.1]: rv = self.dispatch_request()
2021-06-19T01:15:31.312772+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 1499, in dispatch_request
2021-06-19T01:15:31.312773+00:00 app[web.1]: return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
2021-06-19T01:15:31.312773+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/dash/dash.py", line 1079, in dispatch
2021-06-19T01:15:31.312774+00:00 app[web.1]: response.set_data(func(*args, outputs_list=outputs_list))
2021-06-19T01:15:31.312774+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/dash/dash.py", line 1010, in add_context
2021-06-19T01:15:31.312775+00:00 app[web.1]: output_value = func(*args, **kwargs)  # %% callback invoked %%
2021-06-19T01:15:31.312775+00:00 app[web.1]: File "/app/Vib-easy-3.py", line 110, in update_output
2021-06-19T01:15:31.312776+00:00 app[web.1]: with nidaqmx.Task() as task:
2021-06-19T01:15:31.312776+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/task.py", line 84, in __init__
2021-06-19T01:15:31.312777+00:00 app[web.1]: self._handle = lib_importer.task_handle(0)
2021-06-19T01:15:31.312777+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/_lib.py", line 178, in task_handle
2021-06-19T01:15:31.312778+00:00 app[web.1]: self._parse_typedefs()
2021-06-19T01:15:31.312778+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/_lib.py", line 241, in _parse_typedefs
2021-06-19T01:15:31.312779+00:00 app[web.1]: version = system.driver_version
2021-06-19T01:15:31.312779+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/system/system.py", line 73, in driver_version
2021-06-19T01:15:31.312780+00:00 app[web.1]: return DriverVersion(self._major_version, self._minor_version,
2021-06-19T01:15:31.312780+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/system/system.py", line 108, in _major_version
2021-06-19T01:15:31.312780+00:00 app[web.1]: cfunc = lib_importer.windll.DAQmxGetSysNIDAQMajorVersion
2021-06-19T01:15:31.312781+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/_lib.py", line 166, in windll
2021-06-19T01:15:31.312781+00:00 app[web.1]: self._import_lib()
2021-06-19T01:15:31.312781+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/nidaqmx/_lib.py", line 218, in _import_lib
2021-06-19T01:15:31.312782+00:00 app[web.1]: raise DaqNotFoundError(
2021-06-19T01:15:31.312783+00:00 app[web.1]: nidaqmx._lib.DaqNotFoundError: Could not find an installation of NI-DAQmx. Please ensure that NI-DAQmx is installed on this machine or contact National Instruments for support.
2021-06-19T01:15:31.317641+00:00 app[web.1]: 10.5.190.247 - - [19/Jun/2021:01:15:31 +0000] "POST /_dash-update-component HTTP/1.1" 500 290 "https://monitoreo-remoto.herokuapp.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36"
2021-06-19T01:15:31.315041+00:00 heroku[router]: at=info method=POST path="/_dash-update-component" host=monitoreo-remoto.herokuapp.com request_id=b613139d-c395-4571-923c-1f6c466a1b2d fwd="187.190.230.255" dyno=web.1 connect=1ms service=131ms status=500 bytes=463 protocol=https

I don't know which part is important, but the following line caught my eye:

nidaqmx._lib.DaqNotFoundError: Could not find an installation of NI-DAQmx. Please ensure that NI-DAQmx is installed on this machine or contact National Instruments for support.

I am using the free Heroku version, but I don't know if anyone in here have ran into this problem.


Solution

  • After many days without an answer I will be posting what I think it was happening, and also post a viable solution that doesn't involve heroku.

    My theory: nidaqmx library in python needs the download from National Instruments. if you do not have it, then it won't work. The installation is only available for windows. I guess the servers of Heroku don't have these files.

    After Heroku, I tried to run my program in pythonanywhere, and even used Docker; none of these methods were working (perhaps I did something wrong, or perhaps it was kind of the same problem from above)

    After many days of reading stuff, searching the web, and trying with different methods, I found a nice and easy solution; ngrok.

    Basically you just need to register, download the zip, unzip it and paste the ngrok.exe in C:/Windows/system32. Add the path to your env variables (check answer from il0v3d0g), and later run your dash app in local server (port 3040 , for example) and finally run the ngrok command in another windows bash cmd

    ngrok http 3040
    

    This will create a "tunnel" between your local host (that is running your dash app) and any other computer from anywhere in the internet with the forwarding address that ngrok is creating. enter image description here

    This is a crude schematic of my "settings" enter image description here

    And in case anybody is wondering what the dash app looks like, I am adding it as well (in the case any engineer like myself is caught in the horrible task of working with remote data fetching)

    #Working program, on dash program folder.
    #Working with bootstrap instead of daq.
    # Se debe instalar bootstrap: pip install bootstrap-core-components
    import dash
    import dash_bootstrap_components as dbc
    import dash_core_components as dcc
    import dash_html_components as html
    from dash.dependencies import Input, Output
    import plotly.graph_objects as go
    from dash.exceptions import PreventUpdate
    import nidaqmx
    from nidaqmx.constants import AcquisitionType
    import numpy as np
    
    app = dash.Dash(__name__)
    
    #Initial conditions to have something in the graph
    trace_1 = go.Scatter(
        x = [],
        y = []
    )
    
    layout = go.Layout(title = 'Título de gráfica')
    fig = go.Figure(data = [trace_1], layout = layout)
    
    app.layout = dbc.Container(
        [
    # Toma todo el espacio de arriba para el título.
            dbc.Row(
                dbc.Col(html.H3('Monitoreo Remoto V-0.3', className = 'text-center text-primary mb-4'), width = 12)
            ),
    # Esto es otra fila que va a tener dos dropdowns y el botón en la misma columna
            dbc.Row(
                [
                    dbc.Col(
                        [   
                            dbc.Button(
                            'Capturar',
                            color = 'primary',
                            id = 'Swtc_1',
                            n_clicks = 0
                            ),
                            dcc.Dropdown(
                            id = 'f_muestreo',
                            value = '2048',
                            multi = False,
                            disabled = False,
                            persistence = 'string',
                            persistence_type = 'session',
                            options = [
                                {'label' : '2048', 'value':'2048'},
                                {'label' : '2560', 'value':'2560'},
                                {'label' : '3200', 'value':'3200'},
                                {'label' : '5120', 'value':'5120'},
                                {'label' : '6400', 'value':'6400'},
                                {'label' : '10240', 'value':'10240'},
                                {'label' : '12800', 'value':'12800'},
                                {'label' : '25600', 'value':'25600'}
                            ],
                            ),
                            dcc.Dropdown(
                            id = 'muestras',
                            value = '2048',
                            multi = False,
                            disabled = False,
                            persistence = 'string',
                            persistence_type = 'session',
                            options = [
                                {'label' : '2048', 'value':'2048'},
                                {'label' : '4096', 'value':'4096'},
                                {'label' : '8192', 'value':'8192'},
                                {'label' : '16384', 'value':'16384'},
                                {'label' : '32768', 'value':'32768'},
                                {'label' : '65536', 'value':'65536'},
                                {'label' : '131072', 'value':'131072'}
                            ],
                            ),
                        ], width = 2
                    ),
    # Dentro de la misma fila, se va a meter una nueva columna; para la gráfica. 
                    dbc.Col(
                        dcc.Graph(id = 'plot_id', figure = fig), width = 9
                    )
                ],
            )
        ]
    )    
    # interaction
    @app.callback(
        Output('plot_id', 'figure'),
        [Input('Swtc_1', 'n_clicks'),
        Input('f_muestreo', 'value'),
        Input('muestras', 'value')]   
    )
    
    def update_output(n_clicks, value_1, value_2):
        changed_id = [p['prop_id'] for p in dash.callback_context.triggered][0]
        if 'n_clicks' in changed_id:
            sample_rate = int(value_1)
            samples_to_acq = int(value_2)
            wait_time = samples_to_acq/sample_rate
    # Name and channel of my NI 9234
            channel_name = 'cDAQBAYO1Mod1/ai0'
    # Not using the trig yet
    #        trig_name = 'cDAQBAYO1Mod1/ai1'
            cont_mode = AcquisitionType.CONTINUOUS
            units_g = nidaqmx.constants.AccelUnits.G
            with nidaqmx.Task() as task:
    # Create accelerometer channel and configure sample clock and trigger specs
                task.ai_channels.add_ai_accel_chan(channel_name, units = units_g)
                task.timing.cfg_samp_clk_timing(sample_rate, sample_mode = cont_mode, samps_per_chan=samples_to_acq)
    # Esto es para el tacómetro, de momento está omitido
    #            task.triggers.start_trigger.cfg_dig_edge_start_trig(trigger_source = trig_name)
        
    #   Reading data from sensor and generating time data with numpy
                ydata = task.read(number_of_samples_per_channel=samples_to_acq)
                xdata = np.linspace(0, wait_time,samples_to_acq)
            
                trace_1 = go.Scatter(
                    x = list(xdata),
                    y = list(ydata)
                )
                layout = go.Layout(title = 'Oscilograma')
                fig = go.Figure(data = [trace_1], layout = layout)
                n_clicks = 0
            return (fig)
        else:
            raise PreventUpdate    
       
    
    if __name__ == '__main__':
        app.run_server(debug = False, port = 3040)