jameshwade commited on
Commit
5b39c6e
·
1 Parent(s): 839ae03

update shiny app

Browse files
Files changed (1) hide show
  1. app.R +30 -41
app.R CHANGED
@@ -1,51 +1,40 @@
1
  library(shiny)
2
  library(bslib)
3
- library(dplyr)
4
- library(ggplot2)
5
 
6
- df <- readr::read_csv("penguins.csv")
7
- # Find subset of columns that are suitable for scatter plot
8
- df_num <- df |> select(where(is.numeric), -Year)
9
 
10
- ui <- page_fillable(theme = bs_theme(bootswatch = "minty"),
11
- layout_sidebar(fillable = TRUE,
12
- sidebar(
13
- varSelectInput("xvar", "X variable", df_num, selected = "Bill Length (mm)"),
14
- varSelectInput("yvar", "Y variable", df_num, selected = "Bill Depth (mm)"),
15
- checkboxGroupInput("species", "Filter by species",
16
- choices = unique(df$Species), selected = unique(df$Species)
17
- ),
18
- hr(), # Add a horizontal rule
19
- checkboxInput("by_species", "Show species", TRUE),
20
- checkboxInput("show_margins", "Show marginal plots", TRUE),
21
- checkboxInput("smooth", "Add smoother"),
22
- ),
23
- plotOutput("scatter")
24
- )
 
25
  )
26
 
27
  server <- function(input, output, session) {
28
- subsetted <- reactive({
29
- req(input$species)
30
- df |> filter(Species %in% input$species)
31
- })
32
-
33
- output$scatter <- renderPlot({
34
- p <- ggplot(subsetted(), aes(!!input$xvar, !!input$yvar)) + list(
35
- theme(legend.position = "bottom"),
36
- if (input$by_species) aes(color=Species),
37
- geom_point(),
38
- if (input$smooth) geom_smooth()
39
  )
40
-
41
- if (input$show_margins) {
42
- margin_type <- if (input$by_species) "density" else "histogram"
43
- p <- p |> ggExtra::ggMarginal(type = margin_type, margins = "both",
44
- size = 8, groupColour = input$by_species, groupFill = input$by_species)
45
- }
46
-
47
- p
48
- }, res = 100)
49
  }
50
 
51
- shinyApp(ui, server)
 
1
  library(shiny)
2
  library(bslib)
3
+ library(vetiver)
 
4
 
5
+ endpoint <-
6
+ vetiver_endpoint("https://jameshwade-penguins-model.hf.space/predict")
 
7
 
8
+ ui <- bslib::page_sidebar(
9
+ sidebar = sidebar(
10
+ selectInput("species", "Select Species",
11
+ choices = c("Adelie", "Chinstrap", "Gentoo")),
12
+ sliderInput("bill_length_mm", "Enter Bill Length (mm):",
13
+ min = 30, max = 60, step = 0.5, value = 45),
14
+ sliderInput("bill_depth_mm", "Enter Bill Depth (mm):",
15
+ min = 10, max = 22, step = 0.5, value = 15),
16
+ sliderInput("flipper_length_mm", "Enter Flipper Length (mm):",
17
+ min = 170, max = 235, step = 0.5, value = 200),
18
+ sliderInput("body_mass_g", "Enter Body Mass (g):",
19
+ min = 2700, max = 6300, step = 10, value = 3500),
20
+ actionButton("predict", "Predict"),
21
+ open = TRUE
22
+ ),
23
+ verbatimTextOutput("info")
24
  )
25
 
26
  server <- function(input, output, session) {
27
+ observe({
28
+ new_data <- data.frame(
29
+ species = input$species,
30
+ bill_length_mm = input$bill_length_mm,
31
+ bill_depth_mm = input$bill_depth_mm,
32
+ flipper_length_mm = input$flipper_length_mm,
33
+ body_mass_g = input$body_mass_g
 
 
 
 
34
  )
35
+ prediction <- predict(endpoint, new_data)
36
+ output$info <- renderPrint(prediction)
37
+ }) |> bindEvent(input$predict)
 
 
 
 
 
 
38
  }
39
 
40
+ shinyApp(ui, server)