Simple R Shiny application demonstrating Weierstrass Function.

# ? 2018 TheFlyingKeyboard and released under MIT License # theflyingkeyboard.net library(shiny) f <- function(x, a = 0.5, b = 15, n = 200) { output = 0 for(i in 0:n){ output = output + (a ^ i) * cos((b ^ i) * i * x) } return(output) } ui <- fluidPage( titlePanel("Weierstrass Function"), plotOutput("plot"), fluidPage( fluidRow( column(2, sliderInput("aSlider", "a:", min = 0.01, max = 0.99, value = 0.5)), column(2, numericInput("bInput", "b:", 13, min = 7, max = NA, step = 2, width = NULL)), column(2, numericInput("nInput", "iterations:", 10, min = 1, max = 200, step = NA, width = NULL)), column(2, textOutput("text")) ) ) ) server <- function(input, output) { output$plot <- renderPlot({ y = f(x = seq(2, 12, 0.01), a = input$aSlider, b = input$bInput, n = input$nInput) plot(seq(2, 12, 0.01), y, type = "l", col = "blue", xlab = "X") output$text <- renderText({paste("B must be >= ", (1 + (3 / 2) * pi) / input$aSlider)}) }) } shinyApp(ui = ui, server = server)
R Shiny Weierstrass Function