Last active
March 2, 2024 03:07
-
-
Save dian161/6b9090383b0a47cde75e608639280e7d to your computer and use it in GitHub Desktop.
Fibonacci Number Shiny App
This file contains hidden or 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 <- fib(as.numeric(input$n)) | |
currentFib<-function(){ | |
fib(as.numeric(input$n)) | |
} | |
output$fib_num<-renderText({ | |
#paste("Fibonacci number for the selected number", input$n, "is=", currentFib) | |
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