下の入力枠にPythonプログラムを入力しShift + Enterを押すか、入力枠右下の▶をクリックして実行してください。
import os
def ls():
display("BOTTUN", target="canvas")
display(os.listdir(), target="canvas")
for file in finput.files:
display(file.name, target="canvas")
#display("Z0", target="canvas")
from js import document, fetch, window
finput = document.getElementById("fileinput")
#display(dir(finput), target="canvas")
async def fileUpload(event):
display("UPLOAD", target="canvas")
for file in finput.files:
tmp = window.URL.createObjectURL(file)
with open(f"./{file.name}", "wb") as dest:
# dest.write(await fetch(tmp).bytearray())
pass
#display("Z1", target="canvas")
# Grab a reference to the file upload input element and add
# the on_change handler (defined above) to process the files.
# input = document.querySelector("input[name=filesel]")
#finput = document.getElementById("fileinput")
#display("Z2", target="canvas")
# input.onchange = on_change
#finput.addEventListener("change", fileUpload)
#display("Z3", target="canvas")
display("X0", target="canvas")
def abc():
display("UPLOAD", target="canvas")
from js import document, fetch, window
display("X1", target="canvas")
def fileUpload(event):
display("UPLOAD", target="canvas")
# For each file the user has selected to upload...
for file in input.files:
# create a temporary URL,
tmp = window.URL.createObjectURL(file)
# fetch and save its content somewhere,
with open(f"./{file.name}", "wb") as dest:
dest.write(await fetch(tmp).bytearray())
# then revoke the tmp URL.
window.URL.revokeObjectURL(tmp)
display("X2", target="canvas")
# Grab a reference to the file upload input element and add
# the on_change handler (defined above) to process the files.
# input = document.querySelector("input[name=filesel]")
input = document.getElementById("fileinput")
# input.onchange = on_change
input.addEventListener("change", fileUpload)
#add_event_listener(input, 'change', fileUpload)
display("X3", target="canvas")
# Python Web演習環境 PyTerm for Mapにようこそ
# 政令指定都市の位置と人口
import folium
import math
cities = [
{"name": "横浜市", "latitude": 35.4437, "longitude": 139.6380, "population": 3771766},
{"name": "大阪市", "latitude": 34.6937, "longitude": 135.5023, "population": 2770520},
{"name": "名古屋市", "latitude": 35.1815, "longitude": 136.9066, "population": 2326683},
{"name": "札幌市", "latitude": 43.0618, "longitude": 141.3545, "population": 1969918},
{"name": "福岡市", "latitude": 33.5904, "longitude": 130.4017, "population": 1642571},
{"name": "川崎市", "latitude": 35.5308, "longitude": 139.7031, "population": 1545604},
{"name": "神戸市", "latitude": 34.6901, "longitude": 135.1955, "population": 1499887},
{"name": "京都市", "latitude": 35.0116, "longitude": 135.7681, "population": 1443486},
{"name": "さいたま市", "latitude": 35.8617, "longitude": 139.6455, "population": 1344850},
{"name": "広島市", "latitude": 34.3853, "longitude": 132.4553, "population": 1185505},
{"name": "仙台市", "latitude": 38.2682, "longitude": 140.8694, "population": 1097814},
{"name": "千葉市", "latitude": 35.6073, "longitude": 140.1063, "population": 979532},
{"name": "北九州市", "latitude": 33.8833, "longitude": 130.8753, "population": 916241},
{"name": "堺市", "latitude": 34.5733, "longitude": 135.4828, "population": 812027},
{"name": "浜松市", "latitude": 34.7108, "longitude": 137.7261, "population": 779780},
{"name": "新潟市", "latitude": 37.9162, "longitude": 139.0364, "population": 772388},
{"name": "熊本市", "latitude": 32.8031, "longitude": 130.7079, "population": 738020},
{"name": "相模原市", "latitude": 35.5533, "longitude": 139.3545, "population": 725087},
{"name": "岡山市", "latitude": 34.6551, "longitude": 133.9195, "population": 715740},
{"name": "静岡市", "latitude": 34.9756, "longitude": 138.3828, "population": 677286}
]
# 地図の生成(日本全体が表示されるように設定)
m = folium.Map(location=[39,138], zoom_start=6)
# データの可視化
for city in cities:
folium.CircleMarker(
[city['latitude'], city['longitude']],
radius=math.sqrt(city['population']) / 30, # 人口を面積に反映(適当なスケールに調整)
color='red',
fill=True,
fill_color='blue',
popup=f'{city["name"]}: {city["population"]}'
).add_to(m)
# 地図の表示
m