Upgrade to Pro — share decks privately, control downloads, hide ads and more …

実践Dash - 手を抜きながら本気で作るデータApplicationの基本と応用 / Das...

実践Dash - 手を抜きながら本気で作るデータApplicationの基本と応用 / Dash for Python and Baseball

PyCon JP 2024 9/28 Talk Session 発表資料

Shinichi Nakagawa

September 28, 2024
Tweet

More Decks by Shinichi Nakagawa

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ • Shinichi Nakagawa(@shinyorke) • ӳޠ͕ۤखͳҎ֎, ׂͱԿͰ΋Ͱ͖ΔΤϯδχΞΛੜۀͱ͠ ͨԿ͔ͷਓʢݱࡏ͸େख֎ࢿITίϯαϧاۀͰSREʣ. • ໺ٿσʔλ෼ੳͱΤϯδχΞϦϯά,

    ࠓ೥ങͬͪΌͬͨϚΠ ϗʔϜʹ໋Λ͔͚͍ͯΔਓ. • Python, Cloud, Data Science, SRE, Agile͋ͨΓ͕ಘҙ. • Google Cloud Partner Top Engineer 2024ड৆. • ਪ͠͸೔ຊϋϜϑΝΠλʔζͱສ೾தਖ਼, MLBશൠ⚾ • ΦΦλχ͞Μ͕45-45ΛܾΊͨ೔ʹ45ࡀʹͳΓ·ͨ͠. ※Developers Boost 2023ొஃ࣌ͷࣸਅʢ2023/12ʣ
  2. ͜ͷൃදΛݟͯ΄͍͠ɾௌ͍ͯ΄͍͠ਓ • Dash΍StreamlitͳͲʮLow-codeʯͳPython Framework͕ؾʹͳΔਓ. • DashΛ࢖͍ͬͯΔ, ໊લ͸஌͍ͬͯΔ͚ͲԿʹ࢖ͬͨΒ🤔తͳٙ໰͕͋Δਓ. • Web Application։ൃʹඞཁͳ஌ࣝͱܦݧ͕͋Δ.

    • ʲඞਢʳDjango΍Flask, Fast APIͰ࡞ͬͨ͜ͱ͋Δͥ. • ʲͰ͖Ε͹ʳAWS΍Google CloudͳΜ͔Ͱެ։ͨ͠ࣄ͋Δͥ. • ʢੈքҰ༗໊ͳʣΦΦλχαϯ͕Կऀ͔஌͍ͬͯΔํ⚾ ※ωλͰొ৔͠·͢
  3. ͓͠ͳ͕͖ - جຊ͔ΒԠ༻, ࣮ફ·Ͱ⚾ • Dashͷجຊ - ͱΓ͋͑ͣ࡞ͬͯಈ͔͢ • DashͷԠ༻

    - ࢓ࣄͰ࢖͏, ެ։͢Δ • ࣮ફฤʮϝδϟʔϦʔάσʔλͷՄࢹԽͱ෼ੳͷDXԽʯ • ࣅͨऀಉ࢜Ͱൺ΂ͯΈΔ - StreamlitͱԿ͕ҧ͏ͷ͔ʁ
  4. σʔλͷऔΓѻ͍ͱScope • Dash͸StatelessͳWeb Framework. σʔλ͸อ࣋ͯ͘͠Ε·ͤΜ. • Pythonͷݴޠ࢓༷తʹ͸, ʮGlobalʯʮLocalʯͷScopeͰઓ͏͜ͱʹ. • Global

    Scope: Globalͳม਺Ͱͷอ࣋. ىಈ࣌ʹऔಘ. • Local Scope: ؔ਺಺Ͱͷอ࣋. DashͰ͸callback಺Ͱݺͼग़͠. • Ͳ͏ͯ͠΋σʔλอ͍࣋ͨ࣌͠͸http session΍֎෦ετϨʔδʹཔΔ.
  5. ೝূೝՄΛ࣮૷͢Δ • OSS൛Dashͱͯ͠͸BasicೝূͷΈରԠ. • Basicೝূ͕NGͷ৔߹, ҎԼͰରԠʢ͓ۚΛ෷͏͔໘౗ͳࣄΛ͢Δ͔ʣ. • Enterprise൛DashͩͱLDAP, SAML, OIDC͕ར༻Մೳ💰

    • Dashͷݩ͸FlaskͳͷͰࣗ෼Ͱ࣮૷͢ΔʢԞͷखͱͯ͠ʣ ※ʮࣗ෼Ͱ࣮૷ʯ͸͔ͳΓͷϦεΫ͕͋ΔͷͰࣗݾ੹೚Ͱ͓ئ͍͠·͢.
  6. Ϋϥ΢υʹσϓϩΠ͢Δʢ=ެ։͢Δʣ • DockerͰContainer Imageͱͯ͠ѻ͏ͷ͕ϕετʢී௨ͷWebΞϓϦಉ༷ʣ. • ࠷ޙʹग़͢ઌ͕AWS, Google Cloud, AzureͳͲͷΫϥ΢υͳΒͳ͓ͷ͜ͱ. •

    ϩʔΧϧͰ࡞ͬͨDashΞϓϦΛͦͷ··Ͱ͸ग़ͤͳ͍ͷͰͪΐͬͱ޻෉͢Δ. 1.Application ServerΛProduction༻ͷ΋ͷʹ͢Δ. 2.Docker Imageͱͯ͠Build͢Δ. 3.Ϋϥ΢υʹσϓϩΠ͢Δ.
  7. σϓϩΠ͢Δ (Google Cloud) • ΞϓϦΛಈ͔͢؀ڥʹՃ͑ͯ, Dockerͷ RegistryͱBuildͷखஈΛ༻ҙ. • Google Cloudͷ৔߹,

    ʮCloud Runʯ ʮArtifact RegistryʯʮCloud BuildʯͰ ࣮ݱՄೳ. • AWSͳͲ, ଞͷΫϥ΢υͰ΋ࣅͨײ͡ʹ ͳΓ·͢.
  8. ʲDashͷ࣮ફʳMPAʢMulti Page Applicationʣ • Dash͸SPA͚ͩͰͳ͘, ෳ਺ϖʔδʢMPAʣͷΞϓϦ͕࣮૷Մೳ. • SPA͡Ό೉͍͠ΞϓϦΛMPAʹ࡞Γม͑Δͷ͸ൺֱత༰қʹՄೳ. • URLݻఆϖʔδʹՃ͑ͯ,

    URLύλʔϯͰಈతϖʔδʹ͢Δ͜ͱ΋Մೳ. • ؤுΕ͹Dash͚ͩͰ΋͋Δఔ౓ͷWebαΠτ͸࡞Εͯ͠·͏. • ͳ͓, Dash͸StatelessͳFrameworkͰσʔλΛ࣋ͨͳ͍ҝ, ϖʔδΛލ͙ σʔλ࿈ܞ͸Φεεϝ͠·ͤΜʢ΍Δͷ͸૬౰ΩπΠͱࢥΘΕΔʣ.
  9. ΦχʔϧɾΫϧʔζ ʢ2024೥ଧٿ଎౓࠷଎Ԧʣ • 5/21ʹ2024೥ͷMLB࠷଎ͱͳΔ, 195.53 km/h ͷೋྥଧΛه࿥ • ϐοπόʔΫɾύΠϨʔζॴଐ, 25ࡀͷएख

    γϣʔτ݉ηϯλʔ • ଧܸ੒੷͸ͦͦ͜͜ྑͦ͞͏ͳ΋ͷͷ, कඋࢦ ඪ͕ѱ͘ѻ͍ʹࠔΓͦ͏ͳ༧ײ. • ͪͳΈʹΦΦλχαϯ͸ࠓγʔζϯ191.83km/ hͷ୯ଧΛه࿥͍ͯ͠Δ.
  10. ΞϩϧσΟεɾνϟοϓϚϯ ʢπʔγʔϜ࠷଎Ԧʣ • 8/7ʹ2024೥ͷMLB࠷଎ͱͳΔ, 172.36 km/hͷπʔ γʔϜʢsinker, ಈ͘ਅͬ௚͙ͷ͜ͱʣΛه࿥ • ͜ͷϘʔϧͷ݁Ռ͸ݟಀ͠ετϥΠΫ.

    • ޚࡀ36ࡀͳ͕Β, ͣͬͱMLBͷ࠷଎Ԧʹ܅ྟ͠ଓ͚ Δਓྨ࠷଎ࠨ࿹. • Կٿஂ΋౉Γา͍ͯݱࡏ͸ϐοπόʔΫɾύΠϨʔ ζॴଐ. • Ͳ͏Ͱ΋͍͍͚ͲύΠϨʔπʹԦ͕ू·͍ͬͯΔ🤔
  11. ࢲʢshinyorkeʣͷݟղɹ˞ݸਓతͳײ૝Ͱ͢ ؾʹͳΔϙΠϯτʢൺ΂ΔΞϨʣ %BTI 4USFBNMJU αΫοͱ࡞ͬͯެ։Ͱ͖Δ͔ ͋Δఔ౓ϖʔδΛσβΠϯ͢Δඞཁ͋Δ  ؾָʹ࡞ͬͯެ։͢Δײ͡Ͱ͸ͳ͍ ྑ͘΋ѱ͘΋ϨΠΞ΢τ͕ܾ·Γ΍͍͢ ͷͰָ͘͢͝ʢ͍͡Δൣғ͸গͳ͍ʣ

    ͔ͬ͠ΓσβΠϯͯ͠࡞ΕΔ͔ ίϯϙʔωϯτͷ૊Έ߹Θͤ σβΠϯ ςʔϚΛ࡞͍͍ͬͯײ͡ʹ࡞ΕΔ 4USFBNMJUಛ༗ͷσβΠϯ͕ड͚ೖΕΒ Εͳ͍৔߹ ٧Ή ࣮૷ɾςετͷײ৮ ίϯϙʔωϯτ͓Αͼ$BMMCBDLͷςετ ࣮૷ʹ͸ۤ࿑͢Δ ίϯϙʔωϯτͷςετ͸֎෦ϥΠϒϥ ϦͰߦ͚Δςετʹ͸ۤ࿑ͦ͠͏ ͦΕͧΕͷݸੑɾಛ௃ શൠతʹσʔλͷՄࢹԽʹڧ͍ Ϛϧνϖʔδߏ੒ͰͷΞϓϦߏங͕Մೳ ೖग़ྗ͕සൟʹ͋Δ ΠϯλϥΫςΟϒ ͳΞϓϦͳΒ4USFBNMJU$IBU΋࡞ΕΔ
  12. DashͱStreamlitʢͱଞͷαʔϏεʣ͸࢖͍෼͚͕٢ • ಉ͡Low-code FrameworkͰ΋໨తɾڧΈ͕ҧ͏ͷͰ࢖͍෼͚Α͏. • άϥϑ΍ϏδϡΞϥΠθʔγϣϯΛΰϦοͱ΍ΔͳΒDash. • Chat΍FormͳͲͷΠϯλϥΫςΟϒͳΞϓϦ͸Streamlit. • ͲͪΒʹͯ͠΋,

    Tableau΍Looker StudioͳͲͷαʔϏεͰ࣮૷ͤͣʹ ࡁΉͳΒͦΕʹӽͨ͜͠ͱ͸ແ͍ʢ࣮຿্ͷҙࢥܾఆͱͯ͠͸ʣ. • ͲΜͳLow-codeͰ΋ͪΌΜͱ΍Ζ͏ͱ͢ΔͱLow͡Όͳ͘ͳΔ(ry
  13. զࢥ͏&ࠓޙͷల๬. • SoIʢSystem of InsightʣͳػೳΛDashͰΨνͰ૊ΉΞΠσΞ, զͳ͕Βྑ͍ ΞΠσΞͩͬͨ. ࡞Γͳ͕ΒՄࢹԽ΍ΞϓϦͷΞΠσΞ͕ര஀ͨ͠ͷͰ֓೦࣮ ূʢPoCʣతʹ΋ྑ͔ͬͨ. •

    Ұํ, ΍ͬͺTableau΍Looker StudioͳΜ͔Ͱ૊Ίͨ΄͏ָ͕͍͍ͩ͠Αͳ ͱ…͜͜·ͰຊؾͰΞϓϦ࡞ΔͱେมͬͪΌେมʢೝূೝՄͱ͔໘౗ʣ. • ࠓޙͰ͕͢, ੜ੒AIͰʮ΍͖͏AIʯͳΤʔδΣϯτ࡞ͬͯͦΕͱձ࿩͢Δະདྷ Λݟਾ͍͑ͯ·͢, Streamlitͱ͔Ͱ͜Ε΋࣮ݧ͢ΔͷͰ͸ͳ͔Ζ͏͔স.
  14. ʲAppendixʳࢀߟจݙ • Dash Document https://dash.plotly.com/ • Baseball savant https://baseballsavant.mlb.com/ •

    https://shinyorke.hatenablog.com/entry/baseball-data- transformation-2024 ※࠷ॳͷDash MPAࣄྫʢࣗ෼ͷϒϩάʣ