My PLOTLY Shiny App Markdown

This is an R Markdown document. My Shiny App is in the following link: https://illyabjazevic.shinyapps.io/PLOTLYshinyAPP/.

This Shiny App contains Petal Length Exploratory Data Analysis.

You can see the data, a summary, a histogram, a boxplot, a scatter plot, a linear regression plot, and a density plot.

The Shiny App has PLOTLY features for the density plot, the scatter plot, and the linear regression plot.

The histogram can be changed selecting the bin number.

In this website, you can see the code of the Shiny App, but as it was said before, if you want to access the Shiny App online, you need to go to the following link:

https://illyabjazevic.shinyapps.io/PLOTLYshinyAPP/.

library(shiny)
## Warning: package 'shiny' was built under R version 4.0.5
library(ggplot2)
library(datasets)
data("iris")
str(iris)
## 'data.frame':    150 obs. of  5 variables:
##  $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
##  $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
##  $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
##  $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
##  $ Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
# Define UI for random distribution app ----
ui <- fluidPage(
  
  # App title ----
  titlePanel("  Tabsets"),
  
  
  
  # Sidebar layout with input and output definitions ----
  sidebarLayout(
    column(4,  
           # Sidebar panel for inputs ----
           # Input: Slider for the number of bins ----
           sliderInput(inputId = "bins",
                       label = h3("  Number of bins:"),
                       min = 1,
                       max = 10,
                       value = 5)
    ),
    # Main panel for displaying outputs ----
    mainPanel(
      
      # Output: Histogram ----
      plotOutput(outputId = "distPlot"),
      
      # Output: Tabset w/ plot, summary, and table ----
      tabsetPanel(type = "tabs",
                  tabPanel("Scatterplot", plotOutput("plot")),
                  tabPanel("Summary", verbatimTextOutput("summary")),
                  tabPanel("Table", tableOutput("table")),
                  tabPanel("Density", plotOutput("density")),
                  tabPanel("BoxPlot" , plotOutput("boxplot")),
                  tabPanel("Regression LIne", plotOutput("regressionline"))
      )
      
    )
  )
)
## This version of bslib is designed to work with rmarkdown version 2.7 or higher.
# Define server logic for random distribution app ----
server <- function(input, output) {
  
  output$distPlot <- renderPlot({
    
    bins <- seq(1, 10, length.out = input$bins + 1)
    
    hist(iris$Petal.Length, breaks = bins, col = "#75AADB", border = "white",
         xlab = "Centimeters",
         main = "Petal Length Analysis - Iris Set")
    
  })
  
  
  # Generate a plot of the data ----
  # Also uses the inputs to build the plot label. Note that the
  # dependencies on the inputs and the data reactive expression are
  # both tracked, and all expressions are called in the sequence
  # implied by the dependency graph.
  output$plot <- renderPlot({
    scatter_plot <- ggplot(data = iris, mapping = aes(x = Petal.Length, y = Petal.Width)) + 
      geom_point(aes(color = Species), size = 4, alpha = 0.8, position = "jitter") +
      xlab("Petal Length (cm)") +
      ylab("Petal Width (cm)") +
      ggtitle("Petal Dimensions - Iris Set") + theme_set(theme_classic())
    
    scatter_plot 
  })
  
  # Generate a summary of the data ----
  output$summary <- renderPrint({
    summary(iris$Petal.Length)
  })
  
  # Generate an HTML table view of the data ----
  output$table <- renderTable({
    iris$Petal.Length
  })
  
  output$density <- renderPlot({
    g <- ggplot(iris, aes(x=Petal.Length,  fill=Species))
    densityData  <- g + geom_density() + 
      labs(title="Density plot", 
           subtitle="Petal Length by Species",
           caption="Source: Iris Set",
           x="Petal Length",
           fill="Species")
    densityData
  })
  
  output$regressionline <- renderPlot({
    ggplot(iris, aes(x = Petal.Length, y = Petal.Width, color = Species)) + geom_point() + 
      geom_smooth(method = "lm", se = T)
  })
  
  output$boxplot <- renderPlot({
    box_plot <- ggplot(data=iris, aes(x=Petal.Length, y=Species)) + geom_boxplot(aes(fill=Species)) + 
      xlab("Petal Length - centimeters") + ggtitle("Petal Length Boxplot - Iris Set")  
    box_plot
  })
  
}

# Create Shiny app ----
shinyApp(ui, server)

Shiny applications not supported in static R Markdown documents