Excel data to table on Dashing Dashboard

0 votes

I have been trying to convert a Dashing widget called spreadsheetDemo to use the Roo GEM to simplify it and allow for it to cater for local and Google Doc Excel files.(Simply the same just with Roo) I began by looking at other widgets and sources (similar to this just to a table not graph) that are already using Roo and I have tried to reuse their code for the file source in place of the original, resulting in my code below. I am trying to use Roo to access the local spreadsheet, take the headings and data for the 6 columns and rows and then push them to a table. I believe my problem may lie with accessing the speadsheet correctly. Everything is on the first workbook and starts in cell A1.

Sources I have used: https:// github.com/Shopify/dashing/issues/78#issuecomment-14940695

http:// stackoverflow.com/questions/29400811/use-with-excel-data-to-display-on-dashing-dashboard/29421179?newreg=5c8c7db27d104f5ab3b855c8ea729bc8

require 'roo'

#Tried using roo-xls as it started throwing errors saying I needed too.
#require 'roo-xls'


EM.kqueue = EM.kqueue?
file_path = "#{Dir.pwd}/spreadsheet.xls"

def fetch_spreadsheet_data(path)
  s = Roo::Excel.new(path)

    ws = workbook.sheets[0]

  # create an array to hold the lines
    rows = Array.new
    header = Array.new

  # other variables
    up = ws.updated.localtime
    up = up.strftime "%d.%m.%Y %H:%M"

    #workbook.default_sheet = workbook.sheets[0]


    # fill lines
    for row in 1..ws.num_rows
      if row == 1
          header.push({ :c1 => ws[row, 1], :c2 => ws[row, 2], :c3 => ws[row, 3], :c4 => ws[row, 4], :c5 => ws[row, 5], :c6 => ws[row, 6]})
      else
        rows.push({ :c1 => ws[row, 1], :c2 => ws[row, 2], :c3 => ws[row, 3], :c4 => ws[row, 4], :c5 => ws[row, 5], :c6 => ws[row, 6]})
      end
    end 
        send_event('spread', :modified => up, :header => header, :rows => rows)
        rescue => err
    #puts "Exception: #{err}"
end



module Handler
  def file_modified
    fetch_spreadsheet_data(path)
  end
end

fetch_spreadsheet_data(file_path)

end

Apr 11, 2022 in Database by Edureka
• 13,670 points
671 views

1 answer to this question.

0 votes

It contains a feature named "Download." The user is prompted to download something when you return something to it. As an example, your code might look like this:

import io
import dash
import dash_html_components as html
from dash.dependencies import Input, Output, State
from dash.exceptions import PreventUpdate
from dash_extensions import Download
import dash_table
from flask import Flask
import pandas as pd

server = Flask(__name__)
app = dash.Dash(server=server)

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/solar.csv')

app.layout = html.Div(
                [
                    Download(id="download"),
                    html.Button("Save",
                                id="save-button"),
                    html.Div("Press button to save data at your desktop",
                             id="output-1"),
                    dash_table.DataTable(
                        id='table',
                        columns=[{"name": i, "id": i} for i in df.columns],
                        data=df.to_dict('records'),
                    )
                ]
            )


@app.callback(
Output("download", "data"),
Input("save-button", "n_clicks"),
State("table", "data"))
def download_as_csv(n_clicks, table_data):
    df = pd.DataFrame.from_dict(table_data)
    if not n_clicks:
      raise PreventUpdate
    download_buffer = io.StringIO()
    df.to_csv(download_buffer, index=False)
    download_buffer.seek(0)
    return dict(content=download_buffer.getvalue(), filename="some_filename.csv")

if __name__ == '__main__':
    app.run_server()

answered Apr 11, 2022 by gaurav
• 23,260 points

Related Questions In Database

0 votes
1 answer

What is the best way to fetch data from table?

Hey Shraddha, I understand your doubts about fetching ...READ MORE

answered May 25, 2019 in Database by sampriti
• 1,120 points
1,750 views
0 votes
1 answer

How to load data of .csv file in MySQL Database Table?

At first, put the dataset in the ...READ MORE

answered Jul 5, 2019 in Database by Reshma
1,128 views
0 votes
0 answers

How to get address, Column Name and Row Name of all marked rows in Excel table as rows in new worksheet

 need the row/column combinations marked with an ...READ MORE

Feb 24, 2022 in Database by Edureka
• 13,670 points
1,697 views
0 votes
1 answer

How to Export Tally Data programmatically to CSV or Excel format

Open data (Ledger/P&L or Balance Sheet) that ...READ MORE

answered Mar 15, 2022 in Database by gaurav
• 23,260 points
2,487 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Easy way to export multiple data.frame to multiple Excel worksheets

To export numerous data frames from R ...READ MORE

answered Mar 25, 2022 in Database by gaurav
• 23,260 points
1,564 views
0 votes
1 answer

How to Export Tally Data programmatically to CSV or Excel format

Tally Data in Excel or PDF: How ...READ MORE

answered Mar 30, 2022 in Database by gaurav
• 23,260 points
4,472 views
0 votes
1 answer

How to run a SQL query on an Excel table?

On Excel tables, how to construct and ...READ MORE

answered Apr 11, 2022 in Database by gaurav
• 23,260 points
737 views
0 votes
1 answer

Importing notepad data to excel (difficult split)

Excel: How to Use It On the Data ...READ MORE

answered Mar 14, 2022 in Database by gaurav
• 23,260 points
351 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP