Recommand · May 21, 2021 0

How to get a text output in shiny, in this case?

I have a little problem with Shiny and general how to create the output.

What I want to have here is that: I would like to collect input from user on the Dashboard(created probably correctly in the code below). Then, I would like to create a dataframe from that inputs and to process it through the loaded model(from input), like below,

y_pred = predict(regressor, newdata=choice)

Output should be simple. That model should give me a value, and I want to have this value printed as an output in the Dashboard.

Unfortunately I don’t know how to do that.

library(shiny)
library(DT)
library(tidyverse)



#---- UI -----

ui <- fluidPage(
  
  titlePanel("Boleslaw Chrobry Dataset Predictions"),

  fileInput("file1", "upload EDS file here",
            multiple = FALSE), 
  
  selectInput("Motyw",
              "Jaka moneta?",
              c("Boleslaw Chrobry" = "Boleslaw Chrobry"
              ),
              #selected,
              multiple = FALSE,
              selectize = TRUE
              #width,
  ),
  sliderInput("Stan", "Zaznacz stan monety w skali 1-38. 
               1 - najgorszy stan
               38 - stan idealny", value = 1, min = 1, max = 38),
  dateInput("date", "Wpisz dzien sprzedazy monety",   value = NULL, min = NULL, max = NULL),
  selectInput("Nominal",
              "Jaki nominal ma ta moneta",
              c("10" = 10,
                "25" = 25
              ),
              #selected,
              multiple = FALSE,
              selectize = TRUE
              #width,
  ),
  selectInput("Rok", "Rok monety", 1925),
  selectInput("Naklad",
              "Jaki byl naklad monety?",
              c("52350" = 52350
              ),
              #selected,
              multiple = FALSE,
              selectize = TRUE
              #width,
  ),
  selectInput("Rok", "Rok monety", 1925),
  selectInput("Waga",
              "Jaka jest waga w [g] monety?",
              c("3" = 3,
                "6" = 6
              ),
              #selected,
              multiple = FALSE,
              selectize = TRUE
              #width,
  ),

  #text("y_pred")
  textOutput("predykcja"),

)



#---- SERVER LOGICS -----

  
server <- function(input, output, session) {
  
  #creating dataframe
  reactiveDF <- reactive({
    req(input$file1)
    df <- readRDS(input$file1$datapath, stringsAsFactors = TRUE)
  choice <-  data.frame(input$Stan,input$Cena,input$Data,input$Nominal,input$Rok,input$Motyw,input$Naklad,input$Waga)
  
  #changing names of columns
  names(choice) <- c('Stan', 'Cena', 'Data', 'Nominal..PLN.', 'Rok', 'Motyw', 'Naklad', 'Waga..g.')
  #creating prediction
  #wyrzucona <- reactive({y_pred = predict(regressor, newdata=choice)
  #})

    #df <- ReadRDS(input$file1$datapath, stringsAsFactors = TRUE)
    
    df$predictions<-predict(file1, newdata = choice)
    return(df)
    
  })
  
  output$predykcja <- renderText({
    df
  })
  

    
    
}
    





#---- CALL APP ----
shinyApp(ui, server)

Are you able to help me here guys? How to get a an output here?