是否可以将破折​​号数据表导出到磁盘上的特定位置或直接导出到 SQL Server? [英] Is it possible to export dash datatable to a specific location on disk or directly to SQL Server?

查看:45
本文介绍了是否可以将破折​​号数据表导出到磁盘上的特定位置或直接导出到 SQL Server?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Dash 中创建了一个工具,用户可以在其中从 SQL Server 中提取数据、过滤掉所需的行并编辑其中一列中的值.现在我必须在 SQL Server 的新表中获取过滤和编辑过的表.

I created a tool in Dash where user pulls data from SQL Server, filters out desired rows and edits values in one of the columns. Now I have to get that filtered and edited table in a new table in SQL Server.

我是 dash 的新手,找不到直接导出到 SQL Server 或将 .csv 导出到磁盘上的特定位置并从那里使用 SQL Server 过程处理它的方法.有没有人遇到过这样的问题并且知道这是否可能?

I'm new to dash and can't find a way to export directly to SQL Server or export .csv to a specific location on disc and handle it with a SQL Server procedure from there. Has anyone had a problem like this and knows if it is even possible?

我设法导出了 .csv,但它进入了下载文件夹.

I managed to export .csv, but it goes into the downloads folder.

推荐答案

这是我创建的示例.

保存"按钮将保存到H://R//filename.csv",因此将代码中的它替换为您想要的文件位置/名称.

The "Save" button will save to "H://R//filename.csv", so replace this in the code with your desired file location/name.

import dash
import dash_table
import dash_html_components as html
from dash.dependencies import Input, Output, State
import pandas as pd
from dash.exceptions import PreventUpdate

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

app = dash.Dash(__name__)

app.layout = html.Div([
            dash_table.DataTable(
                id='table',
                columns=[{"name": i, "id": i} for i in df.columns],
                data=df.to_dict("rows"),
                editable=True
            ),
            html.Button(id="save-button",n_clicks=0,children="Save"),
            html.Div(id="output-1",children="Press button to save changes")
])

@app.callback(
        Output("output-1","children"),
        [Input("save-button","n_clicks")],
        [State("table","data")]
        )

def selected_data_to_csv(nclicks,table1): 
    if nclicks == 0:
        raise PreventUpdate
    else:
        pd.DataFrame(table1).to_csv('H://R//filename.csv',index=False)
        return "Data Submitted"

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

这篇关于是否可以将破折​​号数据表导出到磁盘上的特定位置或直接导出到 SQL Server?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆