All language subtitles for English captions

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,080 --> 00:00:04,080 hey everybody welcome welcome 2 00:00:02,240 --> 00:00:06,480 today i'm going to talk to you about 3 00:00:04,080 --> 00:00:09,360 dash 2.0. 4 00:00:06,480 --> 00:00:12,559 Dash is a library that makes it very 5 00:00:09,360 --> 00:00:15,679 easy to create web apps in python, 6 00:00:12,559 --> 00:00:18,000 especially analytic web apps like the 7 00:00:15,679 --> 00:00:20,160 one that you see in here on the page. 8 00:00:18,000 --> 00:00:21,920 In this tutorial i'm going to tell you 9 00:00:20,160 --> 00:00:24,080 all you need to know in order to get 10 00:00:21,920 --> 00:00:26,240 started with Dash. 11 00:00:24,080 --> 00:00:29,279 At the end of this tutorial not only 12 00:00:26,240 --> 00:00:32,000 will you be able to build this app, I 13 00:00:29,279 --> 00:00:35,280 will also share with you exercises and 14 00:00:32,000 --> 00:00:37,920 learning resources so you can continue 15 00:00:35,280 --> 00:00:39,360 building powerful web apps in python 16 00:00:37,920 --> 00:00:41,920 with Dash. 17 00:00:39,360 --> 00:00:43,760 I divided this tutorial into certain 18 00:00:41,920 --> 00:00:45,520 chapters and sections 19 00:00:43,760 --> 00:00:47,760 for you to rewatch them if you're 20 00:00:45,520 --> 00:00:49,039 interested. Just go under the video and 21 00:00:47,760 --> 00:00:50,719 click on the section that you want to 22 00:00:49,039 --> 00:00:51,440 rewatch. 23 00:00:50,719 --> 00:00:55,039 So, 24 00:00:51,440 --> 00:00:56,320 a dash app is best defined as 25 00:00:55,039 --> 00:00:58,640 components 26 00:00:56,320 --> 00:01:00,239 that are displayed on a page 27 00:00:58,640 --> 00:01:02,960 through the layout 28 00:01:00,239 --> 00:01:04,879 which interact with each other 29 00:01:02,960 --> 00:01:07,040 through the callback. 30 00:01:04,879 --> 00:01:08,560 That is all you need to know. 31 00:01:07,040 --> 00:01:09,600 Components, 32 00:01:08,560 --> 00:01:11,119 Layout, 33 00:01:09,600 --> 00:01:13,680 and Callback. 34 00:01:11,119 --> 00:01:15,280 If you remember those three things, 35 00:01:13,680 --> 00:01:16,240 you can do anything you want to do with 36 00:01:15,280 --> 00:01:17,920 Dash, 37 00:01:16,240 --> 00:01:19,759 especially as you start building out 38 00:01:17,920 --> 00:01:20,560 these apps. 39 00:01:19,759 --> 00:01:24,080 So, 40 00:01:20,560 --> 00:01:27,040 the components are anything from 41 00:01:24,080 --> 00:01:30,880 a date picker, a slider 42 00:01:27,040 --> 00:01:32,960 a check box, a checklist, a radio button 43 00:01:30,880 --> 00:01:35,520 or a dropdown, like the one that you see 44 00:01:32,960 --> 00:01:36,960 here and many many more. 45 00:01:35,520 --> 00:01:38,079 Layout 46 00:01:36,960 --> 00:01:41,280 is 47 00:01:38,079 --> 00:01:42,640 the part of Dash that allows you to 48 00:01:41,280 --> 00:01:45,600 customize 49 00:01:42,640 --> 00:01:47,840 how the components and how your app is 50 00:01:45,600 --> 00:01:50,320 displayed on the page. 51 00:01:47,840 --> 00:01:52,799 So you can use the layout to 52 00:01:50,320 --> 00:01:55,680 have the dropdown appear to the left of 53 00:01:52,799 --> 00:01:57,040 the map or to the right of the graph, on 54 00:01:55,680 --> 00:01:59,119 top of the graph, 55 00:01:57,040 --> 00:02:00,799 maybe you want a sidebar, 56 00:01:59,119 --> 00:02:03,680 maybe you want 57 00:02:00,799 --> 00:02:04,479 tabs, or navigation bar, or a multi-page 58 00:02:03,680 --> 00:02:08,800 app. 59 00:02:04,479 --> 00:02:10,399 Everything is done through the layout. 60 00:02:08,800 --> 00:02:13,599 The callback 61 00:02:10,399 --> 00:02:16,160 is what gives life to the app. The 62 00:02:13,599 --> 00:02:17,120 callback is what allows the app to be 63 00:02:16,160 --> 00:02:20,080 fully 64 00:02:17,120 --> 00:02:22,000 functional and interactive. 65 00:02:20,080 --> 00:02:24,640 So let's build a few apps together so 66 00:02:22,000 --> 00:02:27,120 you can see this in action. 67 00:02:24,640 --> 00:02:29,440 I recommend going into my github, this 68 00:02:27,120 --> 00:02:32,640 link is under the video, 69 00:02:29,440 --> 00:02:34,239 and opening the file where I have the 70 00:02:32,640 --> 00:02:37,280 code for this video. 71 00:02:34,239 --> 00:02:39,680 In fact, this whole github repository 72 00:02:37,280 --> 00:02:41,440 Dash-by-Plotly, and this 73 00:02:39,680 --> 00:02:43,120 Charming Data channel - 74 00:02:41,440 --> 00:02:46,319 the purpose of these 75 00:02:43,120 --> 00:02:47,360 is to teach you Dash, teach you Plotly, and 76 00:02:46,319 --> 00:02:49,360 also 77 00:02:47,360 --> 00:02:52,080 help you understand how to build web 78 00:02:49,360 --> 00:02:52,879 apps in Python. 79 00:02:52,080 --> 00:02:55,200 So, 80 00:02:52,879 --> 00:02:56,239 go to Good-to-know. This link is under 81 00:02:55,200 --> 00:02:57,280 the video. 82 00:02:56,239 --> 00:02:59,040 Go to 83 00:02:57,280 --> 00:03:01,920 Dash 2.0, 84 00:02:59,040 --> 00:03:05,440 and here you have all the files in 85 00:03:01,920 --> 00:03:07,519 python if you're using pycharm or VS 86 00:03:05,440 --> 00:03:09,680 Code. And here you have 87 00:03:07,519 --> 00:03:11,760 Jupyter Notebook files. 88 00:03:09,680 --> 00:03:14,480 We also have a few exercises that I 89 00:03:11,760 --> 00:03:15,519 built for you and some solutions 90 00:03:14,480 --> 00:03:19,760 that 91 00:03:15,519 --> 00:03:22,400 you can do in order to better learn Dash 92 00:03:19,760 --> 00:03:23,440 and feel stronger with it. 93 00:03:22,400 --> 00:03:24,640 Now, 94 00:03:23,440 --> 00:03:27,840 in case 95 00:03:24,640 --> 00:03:31,280 you do not have Python on your computer 96 00:03:27,840 --> 00:03:33,120 or you don't have Pycharm or VS Code or 97 00:03:31,280 --> 00:03:36,319 Spider installed, 98 00:03:33,120 --> 00:03:38,080 you can also run the code 99 00:03:36,319 --> 00:03:40,640 for this tutorial, 100 00:03:38,080 --> 00:03:42,080 and any other piece of code on my github 101 00:03:40,640 --> 00:03:44,959 repository, 102 00:03:42,080 --> 00:03:46,560 you can run it on your browser, directly 103 00:03:44,959 --> 00:03:48,480 online. 104 00:03:46,560 --> 00:03:50,560 You don't need to use your computer. If 105 00:03:48,480 --> 00:03:52,560 you want to do that, go all the way down 106 00:03:50,560 --> 00:03:54,480 in my Readme, 107 00:03:52,560 --> 00:03:57,599 copy the link 108 00:03:54,480 --> 00:04:01,280 right here, and paste it into your web 109 00:03:57,599 --> 00:04:03,760 browser like this. This will allow you to 110 00:04:01,280 --> 00:04:07,280 execute everything online. Just follow 111 00:04:03,760 --> 00:04:09,280 the instructions on this gif. 112 00:04:07,280 --> 00:04:10,959 All right so let's get started. I'm going 113 00:04:09,280 --> 00:04:15,519 to open my code, 114 00:04:10,959 --> 00:04:17,680 we're going to start with hello-world.py. 115 00:04:15,519 --> 00:04:18,560 So open this piece of code, this Python 116 00:04:17,680 --> 00:04:20,239 file 117 00:04:18,560 --> 00:04:21,440 from the github 118 00:04:20,239 --> 00:04:23,600 and 119 00:04:21,440 --> 00:04:26,720 let's let's see what exactly is 120 00:04:23,600 --> 00:04:30,160 happening inside this file. 121 00:04:26,720 --> 00:04:33,120 So first of all, we're importing the two 122 00:04:30,160 --> 00:04:38,160 libraries that we need for this Dash app. 123 00:04:33,120 --> 00:04:40,840 First we import Dash and Core Components, 124 00:04:38,160 --> 00:04:43,600 and then we import Dash Bootstrap 125 00:04:40,840 --> 00:04:45,680 Components. These are components that 126 00:04:43,600 --> 00:04:48,160 will help you style your app and 127 00:04:45,680 --> 00:04:50,000 customize your layout and do many other 128 00:04:48,160 --> 00:04:52,720 things as well. 129 00:04:50,000 --> 00:04:55,440 If you don't have Dash or Dash Bootstrap 130 00:04:52,720 --> 00:04:58,479 installed, you have to open your command 131 00:04:55,440 --> 00:05:01,360 prompt or your terminal 132 00:04:58,479 --> 00:05:02,400 and pip install these two libraries just 133 00:05:01,360 --> 00:05:04,240 like this. 134 00:05:02,400 --> 00:05:06,880 Terminal, 135 00:05:04,240 --> 00:05:09,919 pip install Dash and then pip install 136 00:05:06,880 --> 00:05:13,120 Dash Bootstrap Components, and this app 137 00:05:09,919 --> 00:05:14,000 will run successfully. 138 00:05:13,120 --> 00:05:16,479 Now, 139 00:05:14,000 --> 00:05:18,320 the first part of a Dash app, remember, 140 00:05:16,479 --> 00:05:20,880 are components, 141 00:05:18,320 --> 00:05:21,759 so let's build our components. 142 00:05:20,880 --> 00:05:24,720 Here, 143 00:05:21,759 --> 00:05:27,520 we start our Dash app and we choose a 144 00:05:24,720 --> 00:05:30,479 Dash Bootstrap theme. In this case the 145 00:05:27,520 --> 00:05:34,000 theme is called BOOTSTRAP. 146 00:05:30,479 --> 00:05:36,720 This will almost always be the same. 147 00:05:34,000 --> 00:05:39,759 Then we start building our components. 148 00:05:36,720 --> 00:05:43,039 In this case I'm building a variable 149 00:05:39,759 --> 00:05:46,080 called mytext, and this mytext variable 150 00:05:43,039 --> 00:05:48,160 is actually a Markdown component. It's a 151 00:05:46,080 --> 00:05:49,840 Dash Core Component 152 00:05:48,160 --> 00:05:51,199 Markdown. 153 00:05:49,840 --> 00:05:53,360 The property 154 00:05:51,199 --> 00:05:54,800 of this, the children property of the 155 00:05:53,360 --> 00:05:58,160 Markdown 156 00:05:54,800 --> 00:06:01,680 is a string in this case. 157 00:05:58,160 --> 00:06:04,319 And this is markdown um format, 158 00:06:01,680 --> 00:06:06,319 so this will appear on the page as an h1 159 00:06:04,319 --> 00:06:08,880 or as a Header. 160 00:06:06,319 --> 00:06:10,800 After we build our components 161 00:06:08,880 --> 00:06:13,360 we have our layout. 162 00:06:10,800 --> 00:06:14,479 And we put the component inside the 163 00:06:13,360 --> 00:06:17,280 layout 164 00:06:14,479 --> 00:06:19,600 for this to be displayed on the page. So 165 00:06:17,280 --> 00:06:21,360 if we run this app, 166 00:06:19,600 --> 00:06:23,520 click on this, 167 00:06:21,360 --> 00:06:26,880 we'll see our Markdown component: "hello 168 00:06:23,520 --> 00:06:29,360 world let's build web apps in Python". 169 00:06:26,880 --> 00:06:32,319 This is exactly what we put here. 170 00:06:29,360 --> 00:06:37,440 If i want to change that I can say 171 00:06:32,319 --> 00:06:37,440 "hi world", and then re-run the app 172 00:06:38,000 --> 00:06:43,360 and that will that will change the title 173 00:06:40,960 --> 00:06:46,479 of the app. We can go back here, 174 00:06:43,360 --> 00:06:47,600 refresh, and now we see "hi world". 175 00:06:46,479 --> 00:06:49,280 Now, 176 00:06:47,600 --> 00:06:51,039 this app is 177 00:06:49,280 --> 00:06:53,759 not interactive. 178 00:06:51,039 --> 00:06:54,720 If we want to add interactivity to the 179 00:06:53,759 --> 00:06:58,560 app 180 00:06:54,720 --> 00:07:00,639 that is when we have to use the callback. 181 00:06:58,560 --> 00:07:04,560 So let's open 182 00:07:00,639 --> 00:07:07,280 this file: interactive-app.py 183 00:07:04,560 --> 00:07:09,599 and let's see what is happening here. 184 00:07:07,280 --> 00:07:12,800 Here we import the same 185 00:07:09,599 --> 00:07:15,599 um the same libraries, but we also import 186 00:07:12,800 --> 00:07:17,759 output and input, which is part of the 187 00:07:15,599 --> 00:07:20,240 callback. 188 00:07:17,759 --> 00:07:22,880 Then we build our components, we're 189 00:07:20,240 --> 00:07:25,360 instantiating and starting our app. We 190 00:07:22,880 --> 00:07:26,960 choose the solar theme, so if you run 191 00:07:25,360 --> 00:07:27,840 this you'll see 192 00:07:26,960 --> 00:07:31,840 a 193 00:07:27,840 --> 00:07:31,840 solar theme. Let's close this. 194 00:07:33,440 --> 00:07:36,720 See this is a darker theme, 195 00:07:38,000 --> 00:07:42,080 and then 196 00:07:39,440 --> 00:07:44,000 we create the same markdown 197 00:07:42,080 --> 00:07:46,400 but this, in this case, the Markdown 198 00:07:44,000 --> 00:07:48,879 children is going to be an empty string. 199 00:07:46,400 --> 00:07:50,479 There's not going to be anything in it. 200 00:07:48,879 --> 00:07:53,120 And then 201 00:07:50,479 --> 00:07:56,720 we're creating myinput which is a Dash 202 00:07:53,120 --> 00:08:00,160 Bootstrap Component Input component. 203 00:07:56,720 --> 00:08:03,199 The value or the value property is going 204 00:08:00,160 --> 00:08:05,759 to be this full string. 205 00:08:03,199 --> 00:08:07,360 And then we're putting both components 206 00:08:05,759 --> 00:08:09,919 that we created 207 00:08:07,360 --> 00:08:11,039 inside the layout, one on top of the 208 00:08:09,919 --> 00:08:13,440 other: 209 00:08:11,039 --> 00:08:15,440 mytext which is the markdown and then 210 00:08:13,440 --> 00:08:18,720 myinput. Now 211 00:08:15,440 --> 00:08:19,840 if we just do that, without the callback, 212 00:08:18,720 --> 00:08:22,560 Control + 213 00:08:19,840 --> 00:08:22,560 question mark, 214 00:08:23,120 --> 00:08:27,360 hashtag it out, 215 00:08:24,720 --> 00:08:30,160 let's rerun the app. 216 00:08:27,360 --> 00:08:31,120 If we do that we'll see 217 00:08:30,160 --> 00:08:33,599 that 218 00:08:31,120 --> 00:08:36,479 we don't have the Markdown, 219 00:08:33,599 --> 00:08:39,680 we only have the dbc Input. 220 00:08:36,479 --> 00:08:40,719 Let's go like this, "let's build web apps 221 00:08:39,680 --> 00:08:42,399 now." 222 00:08:40,719 --> 00:08:45,920 That's it, it doesn't do anything, there is 223 00:08:42,399 --> 00:08:48,000 no interactivity, this is only the Input. 224 00:08:45,920 --> 00:08:49,279 It only represents this. 225 00:08:48,000 --> 00:08:52,080 Why is that? 226 00:08:49,279 --> 00:08:54,480 That is because the children of the 227 00:08:52,080 --> 00:08:57,519 Markdown is empty, there's nothing in 228 00:08:54,480 --> 00:08:58,880 here. So although we put mytext inside 229 00:08:57,519 --> 00:09:01,040 the container, 230 00:08:58,880 --> 00:09:03,279 there is inside the layout, there is 231 00:09:01,040 --> 00:09:05,839 nothing in here. So you can't see 232 00:09:03,279 --> 00:09:08,560 anything inside the Markdown. 233 00:09:05,839 --> 00:09:10,640 But we're going to activate the callback, 234 00:09:08,560 --> 00:09:13,839 we'll hashtag this out, 235 00:09:10,640 --> 00:09:16,160 and activate the callback so if the user 236 00:09:13,839 --> 00:09:18,560 changes anything in the Input 237 00:09:16,160 --> 00:09:21,040 it will also change the title of the 238 00:09:18,560 --> 00:09:23,279 page or the Markdown. 239 00:09:21,040 --> 00:09:24,480 Like this, 240 00:09:23,279 --> 00:09:25,680 go back, 241 00:09:24,480 --> 00:09:28,800 refresh, 242 00:09:25,680 --> 00:09:30,640 and now if I write anything in the page - 243 00:09:28,800 --> 00:09:33,360 "Hi mom 244 00:09:30,640 --> 00:09:33,360 I missed you", 245 00:09:34,080 --> 00:09:38,240 it's going to translate into the 246 00:09:36,959 --> 00:09:39,760 children 247 00:09:38,240 --> 00:09:42,399 of the Markdown. 248 00:09:39,760 --> 00:09:44,560 And that is done through the callback. 249 00:09:42,399 --> 00:09:45,600 And what's cool about Markdown 250 00:09:44,560 --> 00:09:47,760 is that 251 00:09:45,600 --> 00:09:49,440 you can add even links or anything you 252 00:09:47,760 --> 00:09:51,839 want to do really. As long as it has 253 00:09:49,440 --> 00:09:53,440 markdown format, so let's say 254 00:09:51,839 --> 00:09:54,720 "check out", 255 00:09:53,440 --> 00:09:56,480 let's put, 256 00:09:54,720 --> 00:09:57,600 "this link", 257 00:09:56,480 --> 00:10:01,480 like that, 258 00:09:57,600 --> 00:10:03,279 like that. Click https 259 00:10:01,480 --> 00:10:04,800 google.com, 260 00:10:03,279 --> 00:10:08,480 and now you see that this is a link. We 261 00:10:04,800 --> 00:10:11,040 can open it and go to google.com. 262 00:10:08,480 --> 00:10:13,040 So this is all done, this interactivity, 263 00:10:11,040 --> 00:10:15,360 is done through the callback. 264 00:10:13,040 --> 00:10:18,480 Let's see 265 00:10:15,360 --> 00:10:19,839 how we define the callback. 266 00:10:18,480 --> 00:10:22,480 Okay, 267 00:10:19,839 --> 00:10:24,880 so the callback 268 00:10:22,480 --> 00:10:27,440 typically is built from, not typically 269 00:10:24,880 --> 00:10:28,880 but always, is built from a callback 270 00:10:27,440 --> 00:10:31,519 decorator 271 00:10:28,880 --> 00:10:33,760 and a callback function. 272 00:10:31,519 --> 00:10:35,760 The callback decorator 273 00:10:33,760 --> 00:10:38,160 will have an Output 274 00:10:35,760 --> 00:10:40,560 and an Input. 275 00:10:38,160 --> 00:10:43,120 Each Output and Input 276 00:10:40,560 --> 00:10:45,680 have the component ID, 277 00:10:43,120 --> 00:10:48,160 which is the name of the component or 278 00:10:45,680 --> 00:10:50,959 the ID, 279 00:10:48,160 --> 00:10:52,399 and it will have the component property 280 00:10:50,959 --> 00:10:54,240 belonging 281 00:10:52,399 --> 00:10:55,680 to that component. 282 00:10:54,240 --> 00:10:57,600 So in this case, 283 00:10:55,680 --> 00:11:00,480 the Input has, 284 00:10:57,600 --> 00:11:04,880 we're using the value property 285 00:11:00,480 --> 00:11:04,880 of myinput which is this. 286 00:11:04,959 --> 00:11:09,519 And in the Output we're using the 287 00:11:07,519 --> 00:11:12,800 children property 288 00:11:09,519 --> 00:11:16,079 of mytext. Mytext is the Markdown so 289 00:11:12,800 --> 00:11:17,760 we're using this. This is empty right now. 290 00:11:16,079 --> 00:11:20,720 Now, what I mean about, 291 00:11:17,760 --> 00:11:23,040 what I mean when I say "using". 292 00:11:20,720 --> 00:11:24,160 This all comes together, this is all 293 00:11:23,040 --> 00:11:26,720 explained 294 00:11:24,160 --> 00:11:28,800 through the callback function. 295 00:11:26,720 --> 00:11:31,360 The callback function has the callback 296 00:11:28,800 --> 00:11:34,240 signature or the argument 297 00:11:31,360 --> 00:11:35,839 and a returned value. 298 00:11:34,240 --> 00:11:38,640 In this case 299 00:11:35,839 --> 00:11:41,440 the function argument 300 00:11:38,640 --> 00:11:42,640 comes from the component property of the 301 00:11:41,440 --> 00:11:45,279 Input. 302 00:11:42,640 --> 00:11:47,600 It's actually always the case. 303 00:11:45,279 --> 00:11:49,839 Very important, if you understand these 304 00:11:47,600 --> 00:11:51,120 two lines then you understand the 305 00:11:49,839 --> 00:11:53,680 callback. 306 00:11:51,120 --> 00:11:57,120 Function arguments, this, 307 00:11:53,680 --> 00:11:59,200 come from the component property 308 00:11:57,120 --> 00:12:00,720 of the Input. 309 00:11:59,200 --> 00:12:03,440 So in this case, 310 00:12:00,720 --> 00:12:05,680 this comes from the value 311 00:12:03,440 --> 00:12:07,600 of myinput, which is 312 00:12:05,680 --> 00:12:11,120 this right here, right?! 313 00:12:07,600 --> 00:12:12,480 So this is the same as this - 314 00:12:11,120 --> 00:12:14,079 user_input 315 00:12:12,480 --> 00:12:16,720 is this. 316 00:12:14,079 --> 00:12:18,800 And if user goes in there and the user 317 00:12:16,720 --> 00:12:21,519 says I'm going to change the Input and 318 00:12:18,800 --> 00:12:21,519 i'm going to put 319 00:12:22,480 --> 00:12:27,120 "hi there", then now this 320 00:12:27,440 --> 00:12:30,880 goes in here. 321 00:12:29,440 --> 00:12:32,639 Now this 322 00:12:30,880 --> 00:12:35,839 is "hi there" 323 00:12:32,639 --> 00:12:37,120 and if this is "hi there" 324 00:12:35,839 --> 00:12:38,800 then, 325 00:12:37,120 --> 00:12:40,800 I return it 326 00:12:38,800 --> 00:12:43,360 as the user_input, so I'm actually 327 00:12:40,800 --> 00:12:44,480 returning 328 00:12:43,360 --> 00:12:45,760 "hi there" 329 00:12:44,480 --> 00:12:48,639 Now, 330 00:12:45,760 --> 00:12:51,680 return objects or return values are 331 00:12:48,639 --> 00:12:53,200 assigned to the component property of 332 00:12:51,680 --> 00:12:56,079 the Output. 333 00:12:53,200 --> 00:12:59,040 So this string, this "hi there" 334 00:12:56,079 --> 00:13:00,560 is returned to the component property to 335 00:12:59,040 --> 00:13:03,760 the children 336 00:13:00,560 --> 00:13:06,320 of the Output, of the Output. 337 00:13:03,760 --> 00:13:09,600 Right, and the Output is mytext, so this is 338 00:13:06,320 --> 00:13:12,079 going to be returned right here. 339 00:13:09,600 --> 00:13:12,079 "hi there". 340 00:13:12,720 --> 00:13:18,000 But we want this to be interactive so we 341 00:13:15,600 --> 00:13:21,440 can't pre-define the text. 342 00:13:18,000 --> 00:13:22,959 We just use this as, we leave it as user_ 343 00:13:21,440 --> 00:13:25,760 input or you can call it anything you 344 00:13:22,959 --> 00:13:28,880 want. You can call it user_inputs you can 345 00:13:25,760 --> 00:13:30,480 give it any name that you want. 346 00:13:28,880 --> 00:13:32,959 But remember, 347 00:13:30,480 --> 00:13:36,720 your return values are assigned to the 348 00:13:32,959 --> 00:13:39,199 component property of the Output, 349 00:13:36,720 --> 00:13:41,440 so if you have multiple Outputs, you need 350 00:13:39,199 --> 00:13:44,880 to return multiple 351 00:13:41,440 --> 00:13:48,240 values. If you have multiple Inputs 352 00:13:44,880 --> 00:13:51,839 you need to return multiple arguments, 353 00:13:48,240 --> 00:13:55,760 each one representing the component 354 00:13:51,839 --> 00:13:56,800 property of that Input. 355 00:13:55,760 --> 00:13:59,680 Alright, 356 00:13:56,800 --> 00:14:03,120 so now that we understood the callback, 357 00:13:59,680 --> 00:14:04,560 let's see how we add a graph component 358 00:14:03,120 --> 00:14:06,720 to our app. 359 00:14:04,560 --> 00:14:09,760 Close this, 360 00:14:06,720 --> 00:14:13,519 open your app-with-graph file that you 361 00:14:09,760 --> 00:14:14,839 have on the github that I showed you. 362 00:14:13,519 --> 00:14:17,199 And in this 363 00:14:14,839 --> 00:14:18,560 file we're going to import the same 364 00:14:17,199 --> 00:14:20,480 libraries, 365 00:14:18,560 --> 00:14:22,800 but we're also going to import Plotly 366 00:14:20,480 --> 00:14:25,839 Express. Plotly Express 367 00:14:22,800 --> 00:14:27,680 is the library that allows you to build 368 00:14:25,839 --> 00:14:29,199 graphs. 369 00:14:27,680 --> 00:14:31,600 Every graph 370 00:14:29,199 --> 00:14:33,920 plots some data so we also need to 371 00:14:31,600 --> 00:14:37,120 incorporate data into our app, and we're 372 00:14:33,920 --> 00:14:40,959 going to take this medals long 373 00:14:37,120 --> 00:14:43,360 built-in data inside Plotly Express, 374 00:14:40,959 --> 00:14:45,680 and we're going to call it df. This is 375 00:14:43,360 --> 00:14:47,120 our, this is our data frame, this is our 376 00:14:45,680 --> 00:14:50,160 data. 377 00:14:47,120 --> 00:14:51,600 Okay remember, every Dash app is 378 00:14:50,160 --> 00:14:54,160 components 379 00:14:51,600 --> 00:14:56,399 that are displayed on the page through 380 00:14:54,160 --> 00:14:57,600 the layout which interact with each 381 00:14:56,399 --> 00:14:58,399 other 382 00:14:57,600 --> 00:14:59,680 through 383 00:14:58,399 --> 00:15:02,000 the callback. 384 00:14:59,680 --> 00:15:04,160 So let's build our components first. 385 00:15:02,000 --> 00:15:06,320 Here we start our app 386 00:15:04,160 --> 00:15:09,199 but we're going to use a VAPOR theme, and 387 00:15:06,320 --> 00:15:10,800 you can see other themes, just like this, 388 00:15:09,199 --> 00:15:11,680 dot, and it'll give you different 389 00:15:10,800 --> 00:15:13,680 themes. 390 00:15:11,680 --> 00:15:16,079 We're going to use the vapor theme. 391 00:15:13,680 --> 00:15:17,519 Let's actually start this app 392 00:15:16,079 --> 00:15:20,800 and see what we get, and see how the 393 00:15:17,519 --> 00:15:20,800 VAPOR theme looks like. 394 00:15:22,000 --> 00:15:28,240 Here's a VAPOR theme. 395 00:15:24,639 --> 00:15:30,720 And in this app we offer a dropdown 396 00:15:28,240 --> 00:15:33,199 that, if the user changes it, will also 397 00:15:30,720 --> 00:15:36,639 update the type of graph that it did 398 00:15:33,199 --> 00:15:39,040 that is displayed on the page. 399 00:15:36,639 --> 00:15:41,519 So let's see how we do that. 400 00:15:39,040 --> 00:15:44,079 Here we build our components, we're going 401 00:15:41,519 --> 00:15:45,519 to take uh a markdown 402 00:15:44,079 --> 00:15:46,959 and we're going to 403 00:15:45,519 --> 00:15:48,240 populate it 404 00:15:46,959 --> 00:15:51,519 with this 405 00:15:48,240 --> 00:15:55,839 with this title: a header h1 app that 406 00:15:51,519 --> 00:15:55,839 analyzes olympic medals, right here. 407 00:15:56,000 --> 00:16:01,360 And then we're going to use the dcc.dash 408 00:15:58,560 --> 00:16:03,759 core component graph component with an 409 00:16:01,360 --> 00:16:05,199 empty figure. There's nothing in there at 410 00:16:03,759 --> 00:16:07,600 the beginning, 411 00:16:05,199 --> 00:16:09,680 and we're going to uh 412 00:16:07,600 --> 00:16:11,519 a DCC dropdown. 413 00:16:09,680 --> 00:16:14,399 And DCC dropdown, if you click 414 00:16:11,519 --> 00:16:16,880 control left-click, you can see all the 415 00:16:14,399 --> 00:16:19,279 different properties that you can have 416 00:16:16,880 --> 00:16:20,839 inside a dropdown. 417 00:16:19,279 --> 00:16:24,399 We're going to use three different 418 00:16:20,839 --> 00:16:25,440 properties. The "options" property to tell 419 00:16:24,399 --> 00:16:28,399 the app 420 00:16:25,440 --> 00:16:31,360 what options the dropdown will have. 421 00:16:28,399 --> 00:16:33,839 In this case, scatter plot string or bar 422 00:16:31,360 --> 00:16:36,320 plot string. 423 00:16:33,839 --> 00:16:38,160 We're going to define the initial value, 424 00:16:36,320 --> 00:16:40,959 this is the initial "value" that will be 425 00:16:38,160 --> 00:16:44,639 displayed when the page first load, 426 00:16:40,959 --> 00:16:46,320 loads. Bar plot if I first load it. 427 00:16:44,639 --> 00:16:48,240 You'll see that it's going to be bar 428 00:16:46,320 --> 00:16:51,600 plot. 429 00:16:48,240 --> 00:16:53,360 "Clearable" means that I'm not going to 430 00:16:51,600 --> 00:16:56,800 erase the dropdown, It's always going to 431 00:16:53,360 --> 00:16:59,120 be populated with one value. 432 00:16:56,800 --> 00:17:00,480 And then we build our layout, in this 433 00:16:59,120 --> 00:17:01,680 case one 434 00:17:00,480 --> 00:17:04,559 component 435 00:17:01,680 --> 00:17:06,720 above the other, so first mytitle 436 00:17:04,559 --> 00:17:07,520 then my empty graph and then my 437 00:17:06,720 --> 00:17:12,000 downdown. 438 00:17:07,520 --> 00:17:12,000 Here as well, if you hashtag this out 439 00:17:13,679 --> 00:17:18,760 and re-run the app, 440 00:17:15,439 --> 00:17:18,760 you'll see 441 00:17:19,679 --> 00:17:24,720 that the graph is empty 442 00:17:21,520 --> 00:17:27,039 because there is no callback that 443 00:17:24,720 --> 00:17:29,440 creates an interaction between the dropdown 444 00:17:27,039 --> 00:17:30,320 and the graph. We just have a 445 00:17:29,440 --> 00:17:32,559 dropdown 446 00:17:30,320 --> 00:17:34,720 with certain options, 447 00:17:32,559 --> 00:17:36,160 and we have an empty graph, as you can 448 00:17:34,720 --> 00:17:38,720 see here, 449 00:17:36,160 --> 00:17:41,039 this empty empty figure inside the Dash 450 00:17:38,720 --> 00:17:42,400 Core Component Graph. 451 00:17:41,039 --> 00:17:44,320 So let's 452 00:17:42,400 --> 00:17:46,880 connect between 453 00:17:44,320 --> 00:17:50,320 the dropdown and the graph 454 00:17:46,880 --> 00:17:54,320 so every time a user chooses a value 455 00:17:50,320 --> 00:17:55,679 it creates a graph and populates it 456 00:17:54,320 --> 00:17:58,960 into 457 00:17:55,679 --> 00:18:01,919 the figure, right here. 458 00:17:58,960 --> 00:18:04,320 All right, let's just Control-Z. 459 00:18:01,919 --> 00:18:05,679 The callback is back 460 00:18:04,320 --> 00:18:07,679 on the page 461 00:18:05,679 --> 00:18:10,720 and here 462 00:18:07,679 --> 00:18:13,360 we're going to take the dropdown as an 463 00:18:10,720 --> 00:18:15,919 Input, specifically 464 00:18:13,360 --> 00:18:17,760 the component property, the "value" 465 00:18:15,919 --> 00:18:20,720 of the dropdown. 466 00:18:17,760 --> 00:18:23,200 All right, because we have one Input, 467 00:18:20,720 --> 00:18:25,360 meaning one component property, we need 468 00:18:23,200 --> 00:18:26,320 one argument, and we'll call it 469 00:18:25,360 --> 00:18:28,400 user_input. 470 00:18:26,320 --> 00:18:31,200 Now this argument comes from 471 00:18:28,400 --> 00:18:34,720 what is assigned to the value. So this, 472 00:18:31,200 --> 00:18:37,200 in this case, this one is the bar plot. 473 00:18:34,720 --> 00:18:40,400 This is the same as this. 474 00:18:37,200 --> 00:18:44,799 Bar plot, like that, 475 00:18:40,400 --> 00:18:46,080 And then, before we return a value, 476 00:18:44,799 --> 00:18:48,080 we're going to 477 00:18:46,080 --> 00:18:51,679 build the graph 478 00:18:48,080 --> 00:18:53,039 inside the callback function body. 479 00:18:51,679 --> 00:18:55,679 And we're saying, 480 00:18:53,039 --> 00:18:57,360 if the user_input chose 481 00:18:55,679 --> 00:19:00,000 bar plot, 482 00:18:57,360 --> 00:19:03,120 that string, if it's equal to bar plot, 483 00:19:00,000 --> 00:19:07,039 then create this Plotly Express bar plot 484 00:19:03,120 --> 00:19:09,039 with our data, x-axis, y-axis, and color, 485 00:19:07,039 --> 00:19:12,080 and we'll call it "fig". 486 00:19:09,039 --> 00:19:14,720 But if the user chose 487 00:19:12,080 --> 00:19:16,720 in the dropdown a scatter plot, because 488 00:19:14,720 --> 00:19:19,760 this is the second option, this is the 489 00:19:16,720 --> 00:19:22,000 second value that can be chosen. 490 00:19:19,760 --> 00:19:25,039 If they chose that, then build a Plotly 491 00:19:22,000 --> 00:19:27,919 Express scatter plot, so either you have 492 00:19:25,039 --> 00:19:30,880 this figure or you have this figure. 493 00:19:27,919 --> 00:19:33,360 And then you return this fig, remember, 494 00:19:30,880 --> 00:19:35,280 return values, returned objects are 495 00:19:33,360 --> 00:19:38,480 assigned to the component property of 496 00:19:35,280 --> 00:19:40,720 the Output, so this fig 497 00:19:38,480 --> 00:19:41,679 is going to be assigned to the 498 00:19:40,720 --> 00:19:43,600 figure 499 00:19:41,679 --> 00:19:46,160 of my graph component. So it's going to 500 00:19:43,600 --> 00:19:48,640 be assigned right here, 501 00:19:46,160 --> 00:19:48,640 like that. 502 00:19:51,039 --> 00:19:57,600 Okay, and that is why if you go here, 503 00:19:54,799 --> 00:20:00,240 let's rerun this, 504 00:19:57,600 --> 00:20:02,960 with the callback, if you go there you'll 505 00:20:00,240 --> 00:20:04,159 see that if the user chooses 506 00:20:02,960 --> 00:20:06,960 scatter plot 507 00:20:04,159 --> 00:20:08,799 it builds a scatter plot, called "fig" and 508 00:20:06,960 --> 00:20:10,240 returns the fig 509 00:20:08,799 --> 00:20:11,760 to the 510 00:20:10,240 --> 00:20:13,760 DCC 511 00:20:11,760 --> 00:20:16,799 Graph component 512 00:20:13,760 --> 00:20:17,760 figure property, right here. 513 00:20:16,799 --> 00:20:20,159 All right, 514 00:20:17,760 --> 00:20:21,280 now for the most exciting part, we're 515 00:20:20,159 --> 00:20:24,480 going to learn 516 00:20:21,280 --> 00:20:26,080 how to build the app with the Choropleth 517 00:20:24,480 --> 00:20:27,440 map. 518 00:20:26,080 --> 00:20:29,080 Let's pause this. 519 00:20:27,440 --> 00:20:33,480 Let's open Dash 520 00:20:29,080 --> 00:20:33,480 2 point 2 dot py. 521 00:20:35,760 --> 00:20:39,919 And let's actually run it and see what 522 00:20:37,840 --> 00:20:41,520 we have. 523 00:20:39,919 --> 00:20:44,880 Here I'm also going to teach you a 524 00:20:41,520 --> 00:20:44,880 little bit about the layout. 525 00:20:46,480 --> 00:20:50,159 All right, so we have a choropleth map where 526 00:20:48,400 --> 00:20:51,440 we have an animation 527 00:20:50,159 --> 00:20:53,520 play button 528 00:20:51,440 --> 00:20:54,960 and we have a dropdown 529 00:20:53,520 --> 00:20:57,039 that will change 530 00:20:54,960 --> 00:20:58,960 the legend or the color, right. This is 531 00:20:57,039 --> 00:21:00,799 percent of babies born to unmarried 532 00:20:58,960 --> 00:21:02,799 mothers, 533 00:21:00,799 --> 00:21:04,159 or you can change it to suicide 534 00:21:02,799 --> 00:21:06,799 mortality 535 00:21:04,159 --> 00:21:09,280 per 100 000. 536 00:21:06,799 --> 00:21:12,159 And then you can play the animation 537 00:21:09,280 --> 00:21:14,080 to see the difference over the years. 538 00:21:12,159 --> 00:21:15,520 So, 539 00:21:14,080 --> 00:21:17,679 let's see what is happening in this 540 00:21:15,520 --> 00:21:20,000 Python file. 541 00:21:17,679 --> 00:21:22,000 Actually before that we'll take a a 542 00:21:20,000 --> 00:21:24,559 quick commercial break 543 00:21:22,000 --> 00:21:26,000 and say that if uh you've enjoyed the 544 00:21:24,559 --> 00:21:27,039 tutorial so far 545 00:21:26,000 --> 00:21:29,280 and 546 00:21:27,039 --> 00:21:30,400 if you feel that you learned a lot 547 00:21:29,280 --> 00:21:32,240 then, 548 00:21:30,400 --> 00:21:36,000 if you want to show your appreciation, 549 00:21:32,240 --> 00:21:37,840 you can always go into my Patreon and show 550 00:21:36,000 --> 00:21:40,880 your support or 551 00:21:37,840 --> 00:21:43,360 Youtube membership. I'll be 552 00:21:40,880 --> 00:21:45,039 grateful to you if you're interested. 553 00:21:43,360 --> 00:21:46,080 Thank you. 554 00:21:45,039 --> 00:21:47,600 Okay, 555 00:21:46,080 --> 00:21:51,360 so in this case 556 00:21:47,600 --> 00:21:53,120 we're also importing the pandas library, 557 00:21:51,360 --> 00:21:55,280 and we're importing pandas because 558 00:21:53,120 --> 00:21:56,240 because we're going to read 559 00:21:55,280 --> 00:22:00,080 this 560 00:21:56,240 --> 00:22:03,200 CSV sheet, that's on my GitHub, 561 00:22:00,080 --> 00:22:05,039 into a pandas DataFrame, df. 562 00:22:03,200 --> 00:22:09,520 So you need to install pandas if you 563 00:22:05,039 --> 00:22:11,280 don't have pandas on your local computer. 564 00:22:09,520 --> 00:22:13,280 So we're reading this file, which is 565 00:22:11,280 --> 00:22:15,039 actually right here, you can see it, these 566 00:22:13,280 --> 00:22:16,640 are the column names 567 00:22:15,039 --> 00:22:18,240 and these are the rows. 568 00:22:16,640 --> 00:22:21,120 We're going to read this file into a 569 00:22:18,240 --> 00:22:22,720 pandas DataFrame 570 00:22:21,120 --> 00:22:25,200 and then we're going to build our 571 00:22:22,720 --> 00:22:28,320 components that are going to go inside 572 00:22:25,200 --> 00:22:29,840 the layout and interact with each other 573 00:22:28,320 --> 00:22:32,320 in the callback. 574 00:22:29,840 --> 00:22:35,200 So let's see the components. 575 00:22:32,320 --> 00:22:37,360 Here I'm using the LUX theme 576 00:22:35,200 --> 00:22:39,280 I'm building an empty markdown, there's 577 00:22:37,360 --> 00:22:42,960 not going to be anything in there, 578 00:22:39,280 --> 00:22:44,880 an empty figure inside this DCC Graph 579 00:22:42,960 --> 00:22:47,120 and a dropdown 580 00:22:44,880 --> 00:22:49,840 that has initial "value" 581 00:22:47,120 --> 00:22:51,440 of cesarean delivery rate 582 00:22:49,840 --> 00:22:54,640 And the "options" 583 00:22:51,440 --> 00:22:57,600 are the column values of the df, 584 00:22:54,640 --> 00:22:59,840 starting from the third column, zero, one 585 00:22:57,600 --> 00:23:01,840 two. Two is the third, all the way to the 586 00:22:59,840 --> 00:23:04,159 end. So not this one, 587 00:23:01,840 --> 00:23:08,440 not this one, but only from here. All 588 00:23:04,159 --> 00:23:08,440 these columns are the options. 589 00:23:09,039 --> 00:23:14,000 Let's 590 00:23:10,559 --> 00:23:14,000 hashtag out the callback. 591 00:23:14,480 --> 00:23:16,960 And now, 592 00:23:17,360 --> 00:23:22,640 let's see the layout. In the layout we 593 00:23:19,760 --> 00:23:25,280 have a container, now i'm going to 594 00:23:22,640 --> 00:23:28,080 customize the layout a little bit more. 595 00:23:25,280 --> 00:23:30,159 So instead of putting one, 596 00:23:28,080 --> 00:23:32,320 just everything inside the container, I'm 597 00:23:30,159 --> 00:23:33,600 going to define 598 00:23:32,320 --> 00:23:35,840 the row 599 00:23:33,600 --> 00:23:38,720 and then dbc col to define the column 600 00:23:35,840 --> 00:23:40,159 or the column width. So I'm going to say 601 00:23:38,720 --> 00:23:42,000 in this row, 602 00:23:40,159 --> 00:23:44,799 right here in the first row, 603 00:23:42,000 --> 00:23:46,559 we're going to put mytitle, 604 00:23:44,799 --> 00:23:48,960 which is the Markdown empty Markdown, 605 00:23:46,559 --> 00:23:51,120 there's nothing there, 606 00:23:48,960 --> 00:23:53,840 inside as the top row 607 00:23:51,120 --> 00:23:55,279 with six columns wide. 608 00:23:53,840 --> 00:23:57,600 And i'm going to put it in the center of 609 00:23:55,279 --> 00:23:58,799 the page. The second row is going to be 610 00:23:57,600 --> 00:24:01,679 "mygraph" 611 00:23:58,799 --> 00:24:04,159 12 columns wide, and the third row on the 612 00:24:01,679 --> 00:24:06,799 bottom is going to be my dropdown, only 613 00:24:04,159 --> 00:24:09,039 six columns wide. I don't want it to be 614 00:24:06,799 --> 00:24:11,679 like this, you see how it's 12 columns, it's 615 00:24:09,039 --> 00:24:15,039 the full width of the page. I want it to 616 00:24:11,679 --> 00:24:15,039 be only half of the page. 617 00:24:15,120 --> 00:24:18,400 And I'm centering it, 618 00:24:16,799 --> 00:24:20,799 so this is my container, this is my 619 00:24:18,400 --> 00:24:22,400 layout. And you can see because my 620 00:24:20,799 --> 00:24:23,760 callback is 621 00:24:22,400 --> 00:24:26,080 commented out, 622 00:24:23,760 --> 00:24:28,480 there is no interactivity, there is a 623 00:24:26,080 --> 00:24:30,880 an empty graph, there's dropdown 624 00:24:28,480 --> 00:24:33,520 options that don't do anything, 625 00:24:30,880 --> 00:24:35,279 and there is no lay... there's no title 626 00:24:33,520 --> 00:24:37,679 because the title 627 00:24:35,279 --> 00:24:40,480 is our Markdown. You see the first 628 00:24:37,679 --> 00:24:43,120 Markdown, but it's an empty children. 629 00:24:40,480 --> 00:24:44,640 We're going to populate this 630 00:24:43,120 --> 00:24:47,840 according to 631 00:24:44,640 --> 00:24:48,880 the dropdown type string chosen. 632 00:24:47,840 --> 00:24:50,400 All right, 633 00:24:48,880 --> 00:24:54,080 so let's see how we do that. Let's 634 00:24:50,400 --> 00:24:54,080 comment the callback back in. 635 00:24:55,039 --> 00:24:59,039 And now you see that we have here in the 636 00:24:57,279 --> 00:25:01,120 callback decorator, 637 00:24:59,039 --> 00:25:03,840 we have two Outputs 638 00:25:01,120 --> 00:25:05,679 and one Input. 639 00:25:03,840 --> 00:25:07,679 The first Output is 640 00:25:05,679 --> 00:25:09,360 going to represent the component 641 00:25:07,679 --> 00:25:12,720 property "figure" 642 00:25:09,360 --> 00:25:12,720 of our DCC Graph, 643 00:25:13,039 --> 00:25:16,880 right here. 644 00:25:14,880 --> 00:25:18,080 The second Output is the "children" of the 645 00:25:16,880 --> 00:25:21,760 Markdown, 646 00:25:18,080 --> 00:25:24,960 and the Input is the component property 647 00:25:21,760 --> 00:25:27,279 "value" of the dropdown, so whatever 648 00:25:24,960 --> 00:25:30,720 value the user chooses. 649 00:25:27,279 --> 00:25:33,039 Now, remember because we have two outputs 650 00:25:30,720 --> 00:25:34,320 we need to return 651 00:25:33,039 --> 00:25:37,360 two 652 00:25:34,320 --> 00:25:40,480 values, or two variables. This variable 653 00:25:37,360 --> 00:25:40,480 and this variable here. 654 00:25:40,720 --> 00:25:44,880 If you have three outputs you have to 655 00:25:42,320 --> 00:25:48,320 return three variables. 656 00:25:44,880 --> 00:25:50,480 In this case we only have one Input 657 00:25:48,320 --> 00:25:52,640 or component property "value". 658 00:25:50,480 --> 00:25:55,039 So we only need one argument, 659 00:25:52,640 --> 00:25:56,559 and this, we're going to call this the 660 00:25:55,039 --> 00:25:58,320 column_name. 661 00:25:56,559 --> 00:25:59,919 Remember this function argument comes 662 00:25:58,320 --> 00:26:01,360 from the component property. So this 663 00:25:59,919 --> 00:26:03,440 refers to this. 664 00:26:01,360 --> 00:26:06,880 So the value of the dropdown, 665 00:26:03,440 --> 00:26:08,320 the initial value is "cesarean delivery 666 00:26:06,880 --> 00:26:09,840 rate". 667 00:26:08,320 --> 00:26:12,799 So this is like 668 00:26:09,840 --> 00:26:15,679 saying cesarean delivery rate, 669 00:26:12,799 --> 00:26:17,120 cesarean delivery rate, and so on and so 670 00:26:15,679 --> 00:26:19,200 on. 671 00:26:17,120 --> 00:26:21,919 So we're going to take this 672 00:26:19,200 --> 00:26:23,600 and we're saying, print out the column_name 673 00:26:21,919 --> 00:26:24,400 and print the type. This is very 674 00:26:23,600 --> 00:26:26,480 helpful 675 00:26:24,400 --> 00:26:27,760 as you start working with Dash and 676 00:26:26,480 --> 00:26:30,240 creating more 677 00:26:27,760 --> 00:26:32,559 complex callbacks. It's important you 678 00:26:30,240 --> 00:26:34,960 know what 679 00:26:32,559 --> 00:26:37,279 the, what the value looks like that the 680 00:26:34,960 --> 00:26:38,720 user is choosing, and it's important you 681 00:26:37,279 --> 00:26:40,720 know the type 682 00:26:38,720 --> 00:26:42,640 because it might be a list, it might be a 683 00:26:40,720 --> 00:26:46,320 dictionary, it might be a string. 684 00:26:42,640 --> 00:26:47,440 You need to know what type it is. 685 00:26:46,320 --> 00:26:49,919 So here, 686 00:26:47,440 --> 00:26:51,600 we're going to build the Plotly Express 687 00:26:49,919 --> 00:26:54,880 Choropleth map, 688 00:26:51,600 --> 00:26:56,960 and I just took this example from this, 689 00:26:54,880 --> 00:26:59,440 from the Python documentation, 690 00:26:56,960 --> 00:27:02,400 and I just changed the 691 00:26:59,440 --> 00:27:03,919 parameters of the choropleth map. So we're 692 00:27:02,400 --> 00:27:05,600 using the "df", 693 00:27:03,919 --> 00:27:07,440 location is "STATE" 694 00:27:05,600 --> 00:27:08,480 and then the height is going to be 600 695 00:27:07,440 --> 00:27:09,279 pixels. 696 00:27:08,480 --> 00:27:12,960 And 697 00:27:09,279 --> 00:27:15,039 the animation_frame is "YEAR" so you can, 698 00:27:12,960 --> 00:27:17,760 let's rerun this. 699 00:27:15,039 --> 00:27:19,279 The animation_frame is "YEAR" 700 00:27:17,760 --> 00:27:22,799 so that's why if you play this you'll 701 00:27:19,279 --> 00:27:22,799 see different years pass by. 702 00:27:22,960 --> 00:27:28,399 And the color is the column_name 703 00:27:25,760 --> 00:27:31,039 so if the user chooses 704 00:27:28,399 --> 00:27:34,080 "cesarean delivery rate", 705 00:27:31,039 --> 00:27:35,840 then, the color or the legend is going to 706 00:27:34,080 --> 00:27:39,120 be cesarean 707 00:27:35,840 --> 00:27:41,360 cesarean uh delivery rate. If it's going to 708 00:27:39,120 --> 00:27:43,200 be "drug overdose 709 00:27:41,360 --> 00:27:46,480 mortality" then this is going to be the 710 00:27:43,200 --> 00:27:49,360 color that defines or categorizes the 711 00:27:46,480 --> 00:27:51,520 choropleth map. 712 00:27:49,360 --> 00:27:54,000 And then we just return the figure as 713 00:27:51,520 --> 00:27:56,720 the first object. The first object is the 714 00:27:54,000 --> 00:27:57,520 first component property output, so it's 715 00:27:56,720 --> 00:27:59,520 this. 716 00:27:57,520 --> 00:28:02,799 So I'm returning the "fig" 717 00:27:59,520 --> 00:28:04,000 right here. 718 00:28:02,799 --> 00:28:05,279 "fig". 719 00:28:04,000 --> 00:28:08,080 Like that. 720 00:28:05,279 --> 00:28:09,120 And then the second output property is 721 00:28:08,080 --> 00:28:10,960 "children". 722 00:28:09,120 --> 00:28:13,120 And let's see what I'm returning there. 723 00:28:10,960 --> 00:28:17,120 In this case it's um 724 00:28:13,120 --> 00:28:19,440 it's a concoctinated string, so this is 725 00:28:17,120 --> 00:28:22,640 a hashtag to make this 726 00:28:19,440 --> 00:28:24,960 um an H1 header because it's Markdown. So 727 00:28:22,640 --> 00:28:27,679 now it's bigger, it's like a title, 728 00:28:24,960 --> 00:28:28,799 and this goes into the "children" of the 729 00:28:27,679 --> 00:28:31,919 Markdown. 730 00:28:28,799 --> 00:28:34,320 So if I go to my app, you'll see if I, 731 00:28:31,919 --> 00:28:35,679 "teen birth for 1000", you'll see it's the 732 00:28:34,320 --> 00:28:37,360 title, right here. 733 00:28:35,679 --> 00:28:38,799 And it's an H1 header because it's a lot 734 00:28:37,360 --> 00:28:40,480 bigger. 735 00:28:38,799 --> 00:28:42,720 And this is on top of the page because 736 00:28:40,480 --> 00:28:46,640 remember in the layout 737 00:28:42,720 --> 00:28:46,640 this is the first row "mytitle". 738 00:28:47,760 --> 00:28:52,480 Okay, 739 00:28:49,279 --> 00:28:54,799 so I hope you learned a lot. 740 00:28:52,480 --> 00:28:56,559 I don't want you to stop there. I want, I 741 00:28:54,799 --> 00:28:59,919 built some um, 742 00:28:56,559 --> 00:29:01,600 exercises for you to help speed up your 743 00:28:59,919 --> 00:29:04,240 learning process in Dash and create 744 00:29:01,600 --> 00:29:06,480 these powerful Dash apps. 745 00:29:04,240 --> 00:29:08,720 To see these exercises you can go into 746 00:29:06,480 --> 00:29:12,760 my github, 747 00:29:08,720 --> 00:29:12,760 let me first shut this down, 748 00:29:13,200 --> 00:29:17,919 and in my github go to the 749 00:29:16,159 --> 00:29:20,559 "good to know", 750 00:29:17,919 --> 00:29:22,480 Dash2, and then go to "Exercises". You'll 751 00:29:20,559 --> 00:29:24,720 see here a bunch of assignments and 752 00:29:22,480 --> 00:29:26,080 solutions for every assignment. 753 00:29:24,720 --> 00:29:27,919 Try them out before you look at the 754 00:29:26,080 --> 00:29:29,600 solution. It's really going to help you 755 00:29:27,919 --> 00:29:32,399 learn Dash. 756 00:29:29,600 --> 00:29:34,799 I also created a "learning-resources" for 757 00:29:32,399 --> 00:29:36,320 you, this Markdown file. 758 00:29:34,799 --> 00:29:38,159 And here 759 00:29:36,320 --> 00:29:41,840 there's a few things that I believe 760 00:29:38,159 --> 00:29:41,840 would really help you 761 00:29:41,919 --> 00:29:46,320 learn Dash a lot faster, 762 00:29:43,760 --> 00:29:48,159 instead of reading for hours and hours. 763 00:29:46,320 --> 00:29:50,640 First of all, I have this new book that I 764 00:29:48,159 --> 00:29:52,320 wrote with my friends over the last year. 765 00:29:50,640 --> 00:29:53,200 They're Dash experts. 766 00:29:52,320 --> 00:29:56,080 And 767 00:29:53,200 --> 00:29:59,440 uh it's now in pre-order stage, so 768 00:29:56,080 --> 00:30:02,240 I hope this can help you. Go check it out. 769 00:29:59,440 --> 00:30:04,320 Then we have important app components. 770 00:30:02,240 --> 00:30:06,000 You have the Dash Core Components, and if 771 00:30:04,320 --> 00:30:08,799 you go here and click on, it you'll see 772 00:30:06,000 --> 00:30:11,440 all the Core Components, markdown, text 773 00:30:08,799 --> 00:30:14,159 area, check boxes. 774 00:30:11,440 --> 00:30:16,480 You also have Bootstrap Components 775 00:30:14,159 --> 00:30:18,000 that include the Layout, Form, Fade, 776 00:30:16,480 --> 00:30:20,960 Collapse, really good components, 777 00:30:18,000 --> 00:30:23,200 especially the Card, really nice. 778 00:30:20,960 --> 00:30:25,360 And Mantine Components. This is a 779 00:30:23,200 --> 00:30:26,799 beautiful library that has a bunch of 780 00:30:25,360 --> 00:30:29,279 components here 781 00:30:26,799 --> 00:30:31,600 that can beautify your app and allow you 782 00:30:29,279 --> 00:30:34,080 to create more powerful apps. And all of 783 00:30:31,600 --> 00:30:37,360 this is built on top of Dash, so 784 00:30:34,080 --> 00:30:38,720 completely compatible with Dash. 785 00:30:37,360 --> 00:30:41,360 And then you have the Bootstrap 786 00:30:38,720 --> 00:30:42,960 Components for Layouts, the dbc.Col, the 787 00:30:41,360 --> 00:30:44,480 dbc. 788 00:30:42,960 --> 00:30:46,960 row 789 00:30:44,480 --> 00:30:48,240 to style your layout. 790 00:30:46,960 --> 00:30:50,399 Then you have the Plotly Graphing 791 00:30:48,240 --> 00:30:52,080 Library and Express API. 792 00:30:50,399 --> 00:30:54,559 This is a graphing library where you can 793 00:30:52,080 --> 00:30:56,399 build all the different apps, 794 00:30:54,559 --> 00:30:58,399 graphs. 795 00:30:56,399 --> 00:31:00,559 Plotly Express High Level, so we did 796 00:30:58,399 --> 00:31:03,679 the choropleth. If we go look at the 797 00:31:00,559 --> 00:31:05,120 choropleth right here, 798 00:31:03,679 --> 00:31:08,080 we'll see all 799 00:31:05,120 --> 00:31:09,279 the different types of 800 00:31:08,080 --> 00:31:12,559 attributes 801 00:31:09,279 --> 00:31:14,720 that we can use, so it's good to read. 802 00:31:12,559 --> 00:31:16,080 The Dash Boostrap Sheet, 803 00:31:14,720 --> 00:31:18,960 very powerful. 804 00:31:16,080 --> 00:31:21,279 Let's reload this. This will allow you to 805 00:31:18,960 --> 00:31:23,840 style your app in many different ways 806 00:31:21,279 --> 00:31:25,519 with just a few lines of code. Um if you 807 00:31:23,840 --> 00:31:29,039 want to see the video or introduction to 808 00:31:25,519 --> 00:31:30,399 bootstrap, just click on the video above. 809 00:31:29,039 --> 00:31:32,480 And then you have the Plotly 810 00:31:30,399 --> 00:31:33,600 Community. If you go here, join the Plotly 811 00:31:32,480 --> 00:31:35,200 Community, 812 00:31:33,600 --> 00:31:38,000 this is really going to help you learn 813 00:31:35,200 --> 00:31:40,640 Dash and solve questions that you might 814 00:31:38,000 --> 00:31:42,720 have about Dash or Plotly. So just open 815 00:31:40,640 --> 00:31:44,480 an account, join us, 816 00:31:42,720 --> 00:31:46,880 and contribute to this thriving 817 00:31:44,480 --> 00:31:48,080 community. 818 00:31:46,880 --> 00:31:50,399 Lastly, 819 00:31:48,080 --> 00:31:52,399 if you are done with your app, you're 820 00:31:50,399 --> 00:31:54,960 proud of it, you like it, and you want to 821 00:31:52,399 --> 00:31:57,279 deploy it to the web so you can share it 822 00:31:54,960 --> 00:32:00,880 with your colleagues, friends, 823 00:31:57,279 --> 00:32:02,240 parents, professors, bosses, you can deploy 824 00:32:00,880 --> 00:32:05,120 it using 825 00:32:02,240 --> 00:32:07,279 Dash-tools. This is a new library that 826 00:32:05,120 --> 00:32:09,760 makes it very easy and very quick to 827 00:32:07,279 --> 00:32:11,679 deploy your app to the web. I'll try to 828 00:32:09,760 --> 00:32:14,080 make a youtube tutorial 829 00:32:11,679 --> 00:32:16,080 um in a couple of weeks on this library 830 00:32:14,080 --> 00:32:18,000 as well. 831 00:32:16,080 --> 00:32:20,159 Thank you for joining me, 832 00:32:18,000 --> 00:32:22,240 thank you for hanging in there. 833 00:32:20,159 --> 00:32:24,480 Again, if you like this tutorial, don't 834 00:32:22,240 --> 00:32:26,559 forget to subscribe below. If you want to 835 00:32:24,480 --> 00:32:28,320 show your appreciation on Patreon or 836 00:32:26,559 --> 00:32:29,679 youtube membership or that youtube 837 00:32:28,320 --> 00:32:31,679 Thanks button, 838 00:32:29,679 --> 00:32:33,120 I will be very grateful. 839 00:32:31,679 --> 00:32:33,919 Thanks for watching 840 00:32:33,120 --> 00:32:37,320 and 841 00:32:33,919 --> 00:32:37,320 have a good day. 55768

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.