In [1]:
from pydomo import Domo
from pydomo.datasets import Sorting, DataSetRequest, Schema, Column, ColumnType
import logging

import json
import subprocess
In [2]:
# read the secret, client_id, and scope
client_secret = None
scope = None
client_id = None
api_host = ''

with open("secret.txt", 'r') as secret_file:
    client_secret =

with open("client.txt", 'r') as client_file:
    client_id =

with open("scope.txt", 'r') as scope_file:
    scope =
# link to domo instance
domo = Domo(client_id, client_secret, logger_name="Eric", log_level=logging.INFO, api_host=api_host)

Find our dataset without knowing its ID

(takes 30 seconds to run)

In [ ]:
# get the input and output datasets
to_find = ['BASE|ERIC|Billboard Top 10','BASE|ERIC|Billboard Top 10 OUTPUT']

def find_datasets_by_name(dataset_names, domo):
    datasets = list(domo.datasets.list())
    results = dict()
    for dataset in datasets:
        if dataset['name'] in dataset_names:
            results[dataset['name']] = dataset
    return results
datasets = find_datasets_by_name(to_find, domo)

Read in all data

(Export it to 'input.csv')

In [ ]:
include_csv_header = True
csv_file_path = './input.csv'
csv_download = domo.datasets.data_export_to_file(
    datasets['BASE|ERIC|Billboard Top 10']['id'], csv_file_path, include_csv_header)

Start R Script

In [ ]:
r_script_path = './script_for_domo.R'
command = 'Rscript'
working_dir = '.'
outfile_name = 'output.csv'
args = [working_dir, csv_file_path, outfile_name] # could place several command arguments here
cmd = [command, r_script_path] + args

# run the command and store result
result = subprocess.check_output(cmd, universal_newlines=True) 
# universal newlines tells python to interpret returned output as a string
# and handle both windows and linux newline characters

Replace target dataset in Domo with new data

In [ ]:
    datasets['BASE|ERIC|Billboard Top 10 OUTPUT']['id'], outfile_name, update_method='REPLACE')

Did it work???

In [ ]:
    datasets['BASE|ERIC|Billboard Top 10 OUTPUT']['id'], include_csv_header))
In [100]:
{'BASE|ERIC|Billboard Top 10 OUTPUT': {'id': 'e9d1c87f-6640-421b-9d13-4ad92f9ea525',
  'name': 'BASE|ERIC|Billboard Top 10 OUTPUT',
  'description': "Output of processed data from 'BASE|ERIC|Billboard Top 10' which has id: 54d83e39-b8f8-4d98-8ad3-7deb56c1ef89",
  'rows': 0,
  'columns': 5,
  'owner': {'id': 524807525, 'name': 'Josh Wyatt'},
  'dataCurrentAt': '2019-03-14T05:10:01Z',
  'createdAt': '2019-03-14T01:20:30Z',
  'updatedAt': '2019-03-14T05:10:01Z',
  'pdpEnabled': False},
 'BASE|ERIC|Billboard Top 10': {'id': '54d83e39-b8f8-4d98-8ad3-7deb56c1ef89',
  'name': 'BASE|ERIC|Billboard Top 10',
  'description': 'Test Dataset for Eric',
  'rows': 10,
  'columns': 6,
  'owner': {'id': 1795650661, 'name': 'Blake Allen'},
  'dataCurrentAt': '2019-03-01T01:16:05Z',
  'createdAt': '2019-03-01T01:15:58Z',
  'updatedAt': '2019-03-01T01:16:06Z',
  'pdpEnabled': False}}
In [ ]: