matlab终止以下代码-Tableau-Mathematica-integration:将Mathematica的计算能力和数

  • E5_114054
    了解作者
  • 7.2KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-17 04:31
    上传日期
matlab终止以下代码Mathematica和Tableau集成 Tableau 10.3引入了一项功能,可通过名为tabpy的库将python与tableau集成。 从2021.1版开始,tableau可与R,Python和Matlab等外部服务一起使用。 现在,您可以在Tableau中使用Mathematica的功能。 该存储库包含两个代码: server.nb在Tableau中运行Mathematica代码(应安装Mathematica) web_data_connector.nb将数据直接从Mathematica发送到Tableau 如何在Tableau中运行Mathematica 当您运行tabpy ,它将运行一个本地服务器,该服务器评估具有给定数据的具有python代码的每个请求,并返回结果。 在Mathematica中,借助SocketListen可以发生相同的过程,我们可以运行本地服务器,并定义一个对请求进行编码的函数,将ToExpression应用于请求并返回结果。 如何将Mathematica数据发送到Tableau 考虑一个像tableau 2021.1这样的J
Tableau-Mathematica-integration-main.zip
  • Tableau-Mathematica-integration-main
  • README.md
    6.9KB
  • web_data_connector.nb
    3.7KB
  • server.nb
    3.1KB
  • LICENSE
    1KB
内容介绍
# Mathematica and Tableau integration Tableau 10.3, introduce a feature to integrate python with tableau through a library named `tabpy`. As of version 2021.1, tableau works with external services such as R, Python, and Matlab. Now you can use the power of Mathematica inside Tableau. This repository consists of two code: - `server.nb` to run Mathematica code inside Tableau (Mathematica should be installed) - `web_data_connector.nb` to send data directly from Mathematica to Tableau ## How to run Mathematica in Tableau When you run `tabpy`, it will run a local server that evaluates each request which has python code with the given data and returns back the result. The same procedure can happen in Mathematica with help of `SocketListen`, we could run a local server and by defining a function that encodes the request, apply `ToExpression` to them and returning the result. ## How to send Mathematica data to Tableau Consider a JSON file like http://sample.com/file.json, as tableau 2021.1, there is no way to send that file directly to Tableau. Tableau has its own way to handle data from the web called `Web Data Connector`. In simple terms, you should run some JavaScript code before you handing the data to Tableau. With the help of Mathematica `SocketListen` we could run a server and mimic a web page to send data directly from Mathematica to Tableau. ## Run Mathematica code inside Tableau > Warning: Since Mathematica code uses the `ToExpression` function which can easily be manipulated to harm your computer, only run and open script files that you trust. 1 - First either copy `server.nb` or download the file and run it. The code Automatically runs on port 36000. You could change that to any number as long as it's accessible. 2 - Setup Tableau by going to `Help` > `Setting and Performance` > `Manage Analytics Extension Connections...`. Select `Tabpy/External API`, change `Server` to `localhost` or `127.0.0.1` and port to `36000`: ![](https://i.imgur.com/8e3Znso.png) 3 - Now just like tabpy and running python, you can run Mathematica. Create a `Calculated Field` in Tableau and use Tableau's `SCRIPT_REAL()` or other `SCRIPT_SOMETHING()`. Keep in mind: - Unlike python, there is no need to use `Return` - You can access Tableau's expressions in the code by using `arg1` for the first argument, `arg2` for the second, and so on - Since the kernel is the same that runs your notebook, you have access to all the functions and variables you'd in your notebook ### Compare to Python - Example 1 Objective: increase the given price by one: If you want to do it in python with tabpy, you should run this code in Tableau's `Calculated Field`: ```tableau SCRIPT_REAL("return [i+1 for i in _arg1]",SUM([Price])) ``` Mathematica equivalent: ```tableau SCRIPT_REAL("arg1+1",SUM([Price])) ``` ### Clustering data - Example 2 Here we'll use Mathematica capabilities to cluster `price` and `quantity`: ```tableau SCRIPT_REAL("ClusteringComponents[Transpose[{arg1,arg2}]]",SUM([Price]),SUM([Quantity])) ``` ![](https://i.imgur.com/fBJ0wn6.png) ## Terminating the Server After you'd done your work, run the following code in Mathematica to close the connection and shut down the server: ```mathematica Close[server["Socket"]] DeleteObject[server] ``` ## Possible Issues If your data depend on very small decimals like 10^-9, you might see a little difference between Mathematica calculation and Tableau. Generally, Mathematica will evaluate your code up to 20 digits in decimal but transferring these numbers to Tableau and storing them may distort them by a very little amount. For example, I have a sample sales data with 3 columns `product`, `quantity`, and `price`. The goal is to calculate the average sales by multiplying the sum of `quantity` with the average of `price` for each `product`. Mathematica code: ```tableau SCRIPT_REAL("arg1*arg2",SUM([Quantity]),AVG([Price])) ``` Tableau code: ```tableau SUM([Quantity])*AVG([Price]) ``` Here are the differences between the two columns: ![](https://i.imgur.com/uXK2dT4.png) # Load Mathematica data in Tableau If you want to send dynamic data directly to Tableau without saving it on disk, then this section will help you but beware that loading data with this solution is slower than reading a static file. 1 - Either copy the `web_data_connector.nb` or download the file and run it 2 - Send your data with the `sendToTableau` function, keep in mind: - Because of `jquery` and `tableauwdc` JavaScript libraries, you and tableau should be able to connect to the internet - your data should be a 2-dimensional array - supported data types are: `Real`, `Integer`, `Boolean`, `String`, `Date`, `null` (`Missing` in Mathematica) - `Missing[]` values in data will convert to `null` - if no `Headers` exists, column names for your data automatically generated as `C1` for the first column, `C2` for the second, and ... ```mathematica data = Table[{Now, RandomReal[], RandomChoice[{True, False}], RandomInteger[10], "Test"}, 4]; server1 = sendToTableau[data] ``` 2 - In Tableau, `Data` > `New Data Source` > `Web Data Connector`. In the URL section type `localhost:37000` or `127.0.0.1:37000` ![](https://i.imgur.com/hEKiPT7.png) 3 - When the page loaded, click on `Click here to load` 4 - From now, you can use the `Refresh` button to get the newer version of the data Sample Result (as shown `null` also supported, `Missing` in Mathematica): ![](https://i.imgur.com/E5v7mGw.png) ## Settings You should change the following code inside `SocketListen`, but make sure to terminate the server before re-evaluating the code: ```mathematica (* automatically generated column names *) (* will use {"C1","C2","C3","C4","C5"} *) server1 = setupTableauConnector[data] ``` Your list of names should be the same length as the first row of your data: ```mathematica (* specify column names *) server1 = setupTableauConnector[data, "Headers"->{"Column 1", "Column 2", "Column 3", "Column 4", "Column 5"}]; ``` Changing the port with: ```mathematica (* default port: 37000 *) server1 = setupTableauConnector[data,"Port"->37500]; ``` Change port and specify column names: ```mathematica server1 = setupTableauConnector[data,"Headers"->{"C1","C2","C3","C4","C5"},"Port"->37500]; ``` ## Terminating the Server After you'd done your work, run the following code in Mathematica to close the connection and shut down the server: ``` Close[server1] ``` ## Possible Issues Tableau `Web Data Connector` is built to connect to stable addresses, for example on Tableau 2020.1 which I tested, if you use this method and connect your data via some port, after closing your file, every time you open the file, Tableau tries to connect to the same port and doesn't let you change it unless it connects to that port once. Sometimes that port is in use by another program and you can't use that. The solution is to run on a different port, then open your Tableau file in a text editor, search for the previous port and replace it with the newer one.
评论
    相关推荐
    • TestData:中央存储库,用于存储小型数据集以进行测试
      数据集存储在文件夹中。 每个数据集都应存储在其相应的子文件夹中,并带有一个README文件,该文件提供了该数据集的描述性概述。 释放资产 在推送标签(vx.yz)时会自动生成 贡献 如果您要添加更多数据集,请派生此...
    • Datasets:用于存储数据集存储
      Datasets:用于存储数据集存储
    • data_set:用于机器学习的数据集存储
      数据集 用于机器学习的数据集存储
    • POP909-数据集:这是论文的数据集存储库:POP909:用于音乐编曲生成的流行歌曲数据集
      这是论文的数据集存储库: ISMIR 2020中的。 数据集压缩文件结构 index.xlsx:它包含一个描述每个索引文件夹/文件的baisc信息的列表(名称,每小节拍数,每小节的颤音数和修改时间) 索引文件夹:它包含POP909数据...
    • publicdataset:我的公共数据集存储
      公共数据集 我的公共数据集存储
    • 通过数据集
      威盛数据集存储库包含: 将VIA数据集与两个任务一起使用的过程:对象检测和语义分段。 如何实现到您的自定义数据集中。 下载数据集 文献资料 物体检测 对象检测文件夹包含:数据集文件夹,两个文件.csv(test....
    • ex_datasets:数据集存储
      ex_datasets:数据集存储
    • 法律对话系统数据集
      此外,它还包括各种语言资源,包括培训数据集和会话测试集,这些语言资源是专门为合法的doamin设计的。 session_test_set.xlsx包含旨在测试用户和对话框系统之间所有可能的唯一对话的对话流。 每个对话流都是一个...
    • datasets:OpenTripModel数据集
      存储库包含序列化的OpenTripModel格式的一些数据集数据集仅作为示例提供,并不能保证准确性和最新性。 提供的数据集 当前,提供了以下数据集: 荷兰的环境区。 这是一组位置,用于定义荷兰某些城市的环境区域...
    • ICEWS:探索 ICEWS 数据集
      ICEWS 此存储库中的文件是我为探索 ICEWS 而创建的脚本。 主要目标是了解 ICEWS 源并与其他事件数据集进行比较,尤其是 GDELT。