title: Loading JSON from Python into Google Charts PHP/HTML
body: <p>I would like to include a JSON string generated from a py file in PHP code for Google Charts.</p>
  <p>To generate the JSON string I followed: <a href="https://developers.google.com/chart/interactive/docs/dev/gviz_api_lib" rel="nofollow noreferrer">https://developers.google.com/chart/interactive/docs/dev/gviz_api_lib</a> and the code would end like this:</p>
  <pre><code># Create a JavaScript code string.
  jscode_output = data_table.ToJSCode(&quot;jscode_data&quot;,
                                 columns_order=(&quot;number&quot;, &quot;link quality&quot;),
                                 order_by=&quot;number&quot;)
  # Create a JSON string.
  json_output = data_table.ToJSon(columns_order=(&quot;number&quot;, &quot;link quality&quot;),
                             order_by=&quot;number&quot;)
  </code></pre>
  <p>I then saved the py file as script.py</p>
  <p>Next I use the Google Chart line chart code:</p>
  <pre><code>  &lt;html&gt;
    &lt;head&gt;
      &lt;script type=&quot;text/javascript&quot; src=&quot;https://www.gstatic.com/charts/loader.js&quot;&gt;&lt;/script&gt;
      &lt;script type=&quot;text/javascript&quot;&gt;
        google.charts.load('current', {'packages':['corechart']});
        google.charts.setOnLoadCallback(drawChart);
  
        function drawChart() {
          var data = google.visualization.arrayToDataTable([
            ['Year', 'Sales', 'Expenses'],
            ['2004',  1000,      400],
            ['2005',  1170,      460],
            ['2006',  660,       1120],
            ['2007',  1030,      540]
          ]);
  
          var options = {
            title: 'Company Performance',
            curveType: 'function',
            legend: { position: 'bottom' }
          };
  
          var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
  
          chart.draw(data, options);
        }
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div id=&quot;curve_chart&quot; style=&quot;width: 900px; height: 500px&quot;&gt;&lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>Question: How do I now integrate the script.py file and the json variable into this bit of code? From my understanding the var data line would need to change to this- but I'm not sure if that's correct:</p>
  <pre><code>var data = google.visualization.arrayToDataTable(json)
  </code></pre>
  <p>And how do I run the py script? And I would like to run all this code as PHP to display it on a (local) website but I'm not sure what the safest way to do so is in terms of running py scripts in html/php.</p>