Skip to content

Instantly share code, notes, and snippets.

@vlgul
Forked from dian161/app.R
Last active March 2, 2024 03:10
Show Gist options
  • Save vlgul/1d7dc56b3460944a1b17c1b8222a0147 to your computer and use it in GitHub Desktop.
Save vlgul/1d7dc56b3460944a1b17c1b8222a0147 to your computer and use it in GitHub Desktop.
Fibonacci Number Shiny App
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