-
-
Save vlgul/1d7dc56b3460944a1b17c1b8222a0147 to your computer and use it in GitHub Desktop.
Fibonacci Number Shiny App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
ui<-fluidPage( | |
titlePanel("Fibonacci"), | |
sidebarLayout( | |
sidebarPanel( | |
helpText("Print the Fibonacci Number and it's inverse."), | |
sliderInput('n', label="Number n for fibonacci:", min=0, max=40, value=5) | |
), | |
mainPanel( | |
textOutput("fib_num"), | |
textOutput("fib_num_inv") | |
) | |
) | |
) | |
fib<-function(n){ | |
ifelse(n<3,1,fib(n-1)+fib(n-2)) | |
} | |
server<-function(input, output){ | |
currentFib <- reactive({fib(as.numeric(input$n)) | |
}) | |
} | |
output$fib_num<-renderText({ | |
paste("Fibonacci number for the selected number", input$n, "is=", currentFib()) | |
}) | |
output$fib_num_inv<-renderText({ | |
paste("Fibonacci number for the selected number", input$n, "is=", 1/currentFib()) | |
}) | |
} | |
shinyApp(ui=ui, server=server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment