Answer To: Enter the url to your hosted Shiny app below:
Mohd answered on Dec 05 2021
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("World Population"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30),
submitButton("Submit")
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)
library(readr)
world_pop <- read_csv("/cloud/First_Shiny/data/final1.csv")
# Define server logic required to draw a histogram
server <- function(input, output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x<- world_pop$Population
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
}
# Run the application
shinyApp(ui = ui, server = server)
import requests
from bs4 import BeautifulSoup
import re
import dateutil
result = requests.get("https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population")
assert result.status_code==200
src = result.content
document = BeautifulSoup(src, 'lxml')
table = document.find("table")
assert table.find("th").get_text() == "Rank"
rows = table.find_all("tr") # Note: this works because find_all is resursive by default
df_pop = []
df_con = []
df_per = []
for row in rows[2:-1]:
cells = row.find_all(["td", "th"])
cells_text = [cell.get_text(strip=True) for cell in cells]
(rank, country, region, population, percentage, updated_at, source, comment) = cells_text
# Clean population using a regular expression str("1,404,890,600") -> int(1404890600)
population = int(re.sub(',', '', population))
df_pop.append(population)
# Clean country name
country = re.findall(r'[\w\s()\.]+', country)[0]
df_con.append(country)
# Convert percentage to floats
percentage = float(re.findall(r'[\d\.]+', percentage)[0])
df_per.append(percentage)
# Convert updated_at to date object
updated_at = dateutil.parser.parse(updated_at)
print(f"{rank}, {country}, {population}, {percentage}, {updated_at}, {source}")
1, China, 1411778724, 17.8, 2020-11-01 00:00:00, 2020 census result[3]
2, India, 1385054739, 17.5, 2021-12-02 00:00:00, National population clock[4]
3, United States, 332807897, 4.21, 2021-12-02 00:00:00, National population clock[5]
4, Indonesia, 271350000, 3.43, 2020-12-31 00:00:00, National annual estimate[6]
5, Pakistan, 225200000, 2.85, 2021-07-01 00:00:00, UN projection[2]
6, Brazil, 214024230, 2.7, 2021-12-02 00:00:00, National population clock[7]
7, Nigeria, 211401000, 2.67, 2021-07-01 00:00:00, UN projection[2]
8, Bangladesh, 171798154, 2.17, 2021-12-02 00:00:00, National population clock[8]
9, Russia, 146171015, 1.85, 2021-01-01 00:00:00, National annual estimate[9]
10, Mexico, 126014024, 1.59, 2020-03-02 00:00:00, 2020 census result[10]
11, Japan, 125070000, 1.58, 2021-11-01 00:00:00, Monthly national estimate[11]
12, Ethiopia, 117876000, 1.49, 2021-07-01 00:00:00, UN projection[2]
13, Philippines, 111168967, 1.4, 2021-12-02 00:00:00, Official 2020 census result[12]
14, Egypt, 102634232, 1.3, 2021-12-02 00:00:00, National population clock[13]
15, Vietnam, 97580000, 1.23, 2020-07-01 00:00:00, National annual estimate[14]
16, DR Congo, 92378000, 1.17, 2021-07-01 00:00:00, UN projection[2]
17, Iran, 84992537, 1.07, 2021-12-02 00:00:00, National population clock[15]
18, Turkey, 83614362, 1.06, 2020-12-31 00:00:00, National annual estimate[16]
19, Germany, 83129285, 1.05, 2021-06-30 00:00:00, National quarterly estimate[17]
20, France, 67505000, 0.853, 2021-10-01 00:00:00, Monthly national estimate[18]
21, United Kingdom, 67081234, 0.848, 2020-06-30 00:00:00, National annual estimate[19]
22, Thailand, 66724592, 0.843, 2021-12-02 00:00:00, National population clock[20]
23, South Africa, 60142978, 0.76, 2021-07-01 00:00:00, National annual estimate[21]
24, Tanzania, 59441988, 0.751, 2021-07-01 00:00:00, National annual projection[22]
25, Italy, 59097904, 0.747, 2021-08-30 00:00:00, Monthly national estimate[23]
26, Myanmar, 55294979, 0.699, 2021-07-01 00:00:00, National annual projection[24]
27, South Korea, 51671569, 0.653, 2021-07-01 00:00:00, Monthly national estimate[25]
28, Colombia, 51049498, 0.645, 2021-06-30 00:00:00, National annual projection[26]
29, Kenya, 47564296, 0.601, 2019-08-31 00:00:00, 2019 census result[27]
30, Spain, 47394223, 0.599, 2021-01-01 00:00:00, National semi-annual estimate[28]
31, Argentina, 45808747, 0.579, 2021-07-01 00:00:00, National annual projection[29]
32, Algeria, 44700000, 0.565, 2021-01-01 00:00:00, National annual estimate[30]
33, Sudan, 43997855, 0.556, 2021-12-02 00:00:00, National population clock[31]
34, Uganda, 42885900, 0.542, 2021-07-01 00:00:00, National annual projection[32]
35, Ukraine, 41319838, 0.522, 2021-10-01 00:00:00, Monthly national estimate[33]
36, Iraq, 41190700, 0.521, 2021-07-01 00:00:00, National annual projection[34]
37, Canada, 38495813, 0.486, 2021-12-02 00:00:00, National population clock[35]
38, Poland, 38153000, 0.482, 2021-07-31 00:00:00, Monthly national estimate[36]
39, Morocco, 36443961, 0.461, 2021-12-02 00:00:00, National population clock[37]
40, Uzbekistan, 35235931, 0.445, 2021-12-02 00:00:00, National population clock[38]
41, Saudi Arabia, 35013414, 0.442, 2020-07-01 00:00:00, National annual estimate[39]
42, Peru, 33035304, 0.417, 2021-07-01 00:00:00, National annual projection[40]
43, Afghanistan, 32890171, 0.416, 2020-07-01 00:00:00, National annual estimate[41]
44, Malaysia, 32682600, 0.413, 2021-12-02 00:00:00, National population clock[42]
45, Angola, 32097671, 0.406, 2021-06-30 00:00:00, National annual projection[43]
46, Mozambique, 30832244, 0.39, 2021-07-01 00:00:00, National annual projection[44]
47, Ghana, 30792608, 0.389, 2021-06-27 00:00:00, Provisional 2021 census results[45]
48, Yemen, 30491000, 0.385, 2021-07-01 00:00:00, UN projection[2]
49, Nepal, 30378055, 0.384, 2021-07-01 00:00:00, National annual projection[46]
50, Venezuela, 28705000, 0.363, 2021-07-01 00:00:00, UN projection[2]
51, Ivory Coast, 27087732, 0.342, 2021-07-01 00:00:00, National annual...