This the code so far. I will try to implement the code that you sugested.
Thank you
GUI
#
# This is the user-interface definition of a Shiny web application. You can
# run the application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
#
# https://shiny.posit.co/
#
library(shiny)
library(dplyr)
library(bslib)
datasets <- list(AirPassengers = AirPassengers, CO2 = CO2, Formaldehyde = Formaldehyde, Indometh = Indometh,
LifeCycleSavings = LifeCycleSavings, OrchardSprays = OrchardSprays, Theoph = Theoph,
UKDriverDeaths = UKDriverDeaths, WWWusage = WWWusage, austres = austres,chickwts = chickwts,
esoph = esoph, faithful = faithful, islands = islands, lynx = lynx, nhtemp = nhtemp, precip = precip, randu = randu,
stack.loss = stack.loss, state.area = state.area, state.region = state.region, sunspots = sunspots, BJsales = BJsales,
ChickWeight = ChickWeight, HairEyeColor = HairEyeColor, InsectSprays = InsectSprays, Loblolly = Loblolly, PlantGrowth = PlantGrowth,
Titanic = Titanic, UKgas = UKgas, USPersonalExpenditure = USPersonalExpenditure, WorldPhones = WorldPhones, anscombe = anscombe,
beaver1 = beaver1, co2 = co2, euro = euro, fdeaths = fdeaths, infert = infert, ldeaths = ldeaths, mdeaths = mdeaths,
nottem = nottem, presidenst = presidents, rivers = rivers, stackloss = stackloss, state.center = state.center, state.x77 = state.x77,
swiss = swiss, volcano = volcano, BJsales.lead = BJsales.lead, DNase = DNase, Harman23.cor = Harman23.cor, JohnsonJohnson = JohnsonJohnson,
Nile = Nile, mtcars = mtcars, trees = trees)
ui <- fluidPage(
titlePanel(tags$h2("STATISTICAL ANALYSIS AND PREDICTOR FOR R DATA SETS", style = "color: blue;")),
radioButtons("inDs", "Select dataset:", choices = names(datasets)),
varSelectInput("inVar", "Select variable:", datasets[[1]]),
varSelectInput("inVar1", "Select a second variable:", datasets[[1]]),
tableOutput("outData"),
tableOutput("outData1"),
plotOutput("hist"),
plotOutput("hist2"),
plotOutput("plot", click = "plot_click"),
verbatimTextOutput("info"),
textOutput("summary", container = tags$h3)
%>%
tagAppendAttributes(style= 'color:blue;'),
tableOutput("size"),
tableOutput("sum"),
textOutput("regres")
)
SERVER
```{r}
#
# This is the server logic of a Shiny web application. You can run the
# application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
#
# https://shiny.posit.co/
#
library(shiny)
library(ggplot2)
library(caret)
library(shinyPredict)
library(ISLR2)
library(skimr)
# Define server logic required to draw a histogram
function(input, output, session) {
datasets <- list(AirPassengers = AirPassengers, CO2 = CO2, Formaldehyde = Formaldehyde, Indometh = Indometh,
LifeCycleSavings = LifeCycleSavings, OrchardSprays = OrchardSprays, Theoph = Theoph,
UKDriverDeaths = UKDriverDeaths, WWWusage = WWWusage, austres = austres,chickwts = chickwts,
esoph = esoph, faithful = faithful, islands = islands, lynx = lynx, nhtemp = nhtemp, precip = precip, randu = randu,
stack.loss = stack.loss, state.area = state.area, state.region = state.region, sunspots = sunspots, BJsales = BJsales,
ChickWeight = ChickWeight, HairEyeColor = HairEyeColor, InsectSprays = InsectSprays, Loblolly = Loblolly, PlantGrowth = PlantGrowth,
Titanic = Titanic, UKgas = UKgas, USPersonalExpenditure = USPersonalExpenditure, WorldPhones = WorldPhones, anscombe = anscombe,
beaver1 = beaver1, co2 = co2, euro = euro, fdeaths = fdeaths, infert = infert, ldeaths = ldeaths, mdeaths = mdeaths,
nottem = nottem, presidenst = presidents, rivers = rivers, stackloss = stackloss, state.center = state.center, state.x77 = state.x77,
swiss = swiss, volcano = volcano, BJsales.lead = BJsales.lead, DNase = DNase, Harman23.cor = Harman23.cor, JohnsonJohnson = JohnsonJohnson,
Nile = Nile, mtcars = mtcars, trees = trees)
ds <- reactive( datasets[[input$inDs]] )
observe(updateVarSelectInput(session, "inVar", data = ds()))
observe(updateVarSelectInput(session, "inVar1", data = ds()))
output$outData <- renderTable({
var_char <- as.character(input$inVar)
# deal with race conditions, input$inVar might still include
# a column name from previously selected dataset
req(var_char %in% names(ds()))
ds()[1:12, var_char, drop = FALSE]
}, align = "l")
output$outData1 <- renderTable({
var_char1 <- as.character(input$inVar1)
# deal with race conditions, input$inVar might still include
# a column name from previously selected dataset
req(var_char1 %in% names(ds()))
ds()[1:12, var_char1, drop = FALSE]
}, align = "l")
output$hist <- renderPlot({
ggplot(ds(), aes_string(as.character(input$inVar))) + geom_histogram(binwidth = 2, color = "red", fill = "blue")
}, res = 50)
output$hist2 <- renderPlot({
ggplot(ds(), aes_string(as.character(input$inVar1))) + geom_histogram(binwidth = 2, color = "red", fill = "blue")
}, res = 50)
output$plot <- renderPlot({
ggplot(ds(), aes_string(as.character(input$inVar), as.character(input$inVar1))) + geom_point(color = "red") + geom_line(color = "blue")
}, res = 96)
output$info <- renderText({
paste0("x=", input$plot_click$x, "\ny=", input$plot_click$y)
})
output$summary <- renderText({
paste("SUMMARY STATISTICS")
})
output$size <- renderTable(
as.numeric(dim(ds()))
)
output$sum <- renderTable({
skim(ds())
})
model <- reactive({
#lm(mtcars[, c(input$variable)] ~ mtcars[ , c(input$variable2)], data = mtcars)
lm(req(as.character(input$inVar) %in% names(ds()))~ req(as.character(input$inVar) %in% names(ds())), data = ds())
})
output$regres <- renderText({
model()
})
}