Deploy Dashboard With Python And Plotly/Dash On PythonAnywhere
Related Posts
嗨 大家好
這是aronhack.com的Aron
今天我要教你如何在PythonAnywhere上發佈Dash應用程式
PythonAnywhere是一間網路服務公司
你可以在上面執行你的Python程式碼
這是個很棒的服務
今天我要教你如何使用它\N這是個很棒的服務
今天我要教你如何使用它
並且教你一些小技巧
先來看看課程大綱吧
首先,我會告訴你如何使用客製化網域
如果你自己有一個網站
並且你想在子網域上顯示Python應用程式
你可以照著這個方式做
其次,我會告訴你如何在PythonAnywhere上執行Python程式碼
那我們開始吧
在PythonAnywhere網站中
在右上角,點擊web頁籤
如你所見,我已經有一個網頁應用程式
那我要告訴你的第一件事
就是如何客製網域
aronhack.com是我的網站
我的網站使用的是SiteGround主機
所以我必須到SiteGround後台新增一個CNAME
這裡,我們可以注意一下這個CNAME
它是預設的應用程式網址
讓我們記住它 然後到SiteGround後台
這裡就是SiteGround的會員後台
如果你使用其他的主機服務 你會有不同的後台介面
但無所謂
只要找到對應的選項填入就可以了
OK, 那在DNS Zone Editor裡面
我們往下滑
這裡,我已經新增了
如果你想在自己的主機上做設定
你必須新增一個CNAME
你可以在name的地方新增子網域名稱
像是app
那在resolve to欄位中
我剛可以貼上剛才在PythonAnywhere複製的文字
這一個
一般來說,當你新增一個CNAME後
你可以馬上在網域上看到你的應用程式
OK 讓我們回到PythonAnywhere
往下滑
你可以在這裡指定工作路徑
如果你新增了虛擬環境 則在這裡做設定
在source code field的地方 我們可以查看一下這個路徑
在file頁籤中
在左上角 你可以找到這個專案的路徑
那working directory則是我的根目錄
我沒有更改它
那就保持原本的設定就好
最重要的設定在這裡
讓我們點擊
我們會被導到另外一個頁面
這裡有兩個地方必須做修改
第一個在這裡
改成你的工作路徑
第二個則是你的Python檔案名稱
讓我們回到file頁籤
這表示你必須修改設定檔 才能執行Python檔案
事實上 PythonAnywhere官方提供了一個非常短的文字教學
然而 我猜大部份的人都不知道有這個東西
在這個教學中 它用了Plotly官方提供的範例code
就是這一個
你可以直接複製 到自己的帳號中貼上並測試
順帶一提 Dash是個Python的套件
它是建立在Flask與Plotly.js等套件上
這表示你可以直接使用Dash 不需要額外建立Flask物件
這非常有幫助
我希望這個影片也同樣對你有幫助
這是aronhack.com的Aron
我們下次見 掰掰
Hey guys
This is Aron for aronhack.com
Today I will show you how to deploy your Dash application on PythonAnywhere
PythonAnywhere is a web service
You can deploy your python code on it
It is a great service.
Today I will show you how to do it.\NIt is a great service.
Today I will show you how to do it.
And givs you some tips
Let's see the outline of this tutorial
First, I will tell you how to use your custom domain
If you have a website
and you want to use a subdomain to show your python application on it
You can do with this point
Second, I will tell you how to run your python code on PythonAnywhere
And let's get started
In the PythonAnywhere website
At the right top, click the web tab
As you can see, I have a web application
So the first thing I want to tell you is
how to customize your domain
And aronhack.com is my website
My site is hosted by SiteGround
So I have to go to SiteGround panel to add a CNAME record
And here, we have to take notice of this CNAME
It's the default domain of this application
Let's remember it, and to go SiteGround panel
It is SiteGround member panel
If you use other host service, you have different interface
But it doesn't matter
All you need to do is find the option and fill it
OK, so in the DNS Zone Editor
And let's scroll down
It's here. I have added it
But if you want to add it on your own host
You have to create a CNAME
And the name is the string you want to name it
Like app
And to resolve to field
Let's paste this string copied from PythonAnywhere
It's this one
Usually, when you create a CNAME
You can see your application on your domain immediately
OK. Then let's get back to PythonAnywhere
And let's scroll down
You have to assign you work directory here
And if you use a virtual environment, you can assign it here
And in the source code field, we can check this directory
In file tab
At the left top, you can find your project directory
And the working directory is my root directory
I didn't change it
So just keep it
The most important setting is here
Let's click it
And we will be transfered to another page
There are two lines you have to change
First is here
It's your project directory
And second is your python file name
Let's get back to our file tab
It means you have to change the setting file to execute your python file
Actually, PythonAnywhere official gave a really short text tutorial
However, I guess many people they didn't know it
In this documentation, it used a really simple code from Plotly
This one
You can directly copy and paste and test in your account
By the way, Dash is a Python library
It was built based on Flask, Plotly.js
It means you can use Dash directly without creating a Flask app
It's really helpful
Also, I hope this video is helpful to you
This is Aron for aronhack.com
See you next time. Bye bye