What’s Your Weight

Bhanuprakash

24 April 2017

Weight

What is weight ?

Commonly weight is defined as the force exerted on a body by gravity. This is often expressed in the formula W = mg, where W is the weight, m the mass of the object, and g gravitational acceleration.

On Earth the value of ‘g’ is 9.8 m/s2. It is different for different Planets. Hence, weight also varies with planet.

#Ratio of g value on different planets
z <- data.frame(Planets = c("Mercury","Venus","Mars","Jupiter","Saturn","Uranus","Neptune","Pluto"),RatioToEarth = c(0.378,0.907,0.377,2.36,0.916,0.889,1.12,0.071))
print("Ratio of Gravity Values to that of Earth")
## [1] "Ratio of Gravity Values to that of Earth"
head(z,8)
##   Planets RatioToEarth
## 1 Mercury        0.378
## 2   Venus        0.907
## 3    Mars        0.377
## 4 Jupiter        2.360
## 5  Saturn        0.916
## 6  Uranus        0.889
## 7 Neptune        1.120
## 8   Pluto        0.071

What does our App do

The App provides an interface to the user to check his weight in different planets.

It takes the following parameters as Input

Basis the above, the App provides the Output as the Weight on that particular planet.

How did we build

We have used a Shiny Application in R to build our App. Collecting the User Input in the User Interface and displaying the output upon his submission of the parameters.

We collect the Weight input using a Slider and the Planet of his choice using the radio buttons.

The App also has instructions on how to use the App,which are very easy to understand.

The App is available at https://bhanuprakash.shinyapps.io/FindingVelocity/

The code for the App is available at https://github.com/bpr1989/Data-Products

Well, what makes our App good is

Code details

The UI code that constructs the panel is given below

library(shiny)

shinyUI(fluidPage(
  
  # Application title
  titlePanel("What is you weight ? "),
  
    # Sidebar with a slider input for number of bins 
  sidebarLayout(
    sidebarPanel(
       sliderInput("HoB",
                   "Enter your weight( in Kilograms ):",
                   min = 1,
                   max = 200,
                   value = 70),
       
       radioButtons("planet","Select the Planet",choices = c("Mercury","Venus","Mars","Jupiter","Saturn","Uranus","Neptune","Pluto")),
       
       submitButton("Submit")
    ),
    
    # Show a plot of the generated distribution
    mainPanel(
            
        h3("Your weight will be:"),
       h3(textOutput("Weight")),"Kilograms",
       
       h3("Instructions:"),
       "Weight is a Vector which depends in the gravity of the body, in this case planet, on which it is measured ",
       "This App helps you to check your weight in different Planets of our Solar System. You need to set your Weight (in Kilograms ) using the slider and select the Planet where you want to check your weight. After you have set the appropriate weight and selected the Planet click on Sumbit to check your Weight there"
       
    )
  )
))

Server Side Shiny Code

 library(shiny)
shinyServer(function(input, output) {
output$Weight <- reactive({
# generate bins based on input$bins from ui.R
    x    <- input$HoB 
   z <- data.frame(Planets = c("Mercury","Venus","Mars","Jupiter","Saturn","Uranus","Neptune","Pluto"),Ratio = c(0.378,0.907,0.377,2.36,0.916,0.889,1.12,0.071))
    y <- z[z$Planets == input$planet,]$Ratio
    round(x*y)
    
  })
  
})