I added a function sliderInput
into the following code to define a range for the smooth parameter to read this function
after_tilde <- paste0("ps(", dep_vars, ", lambda = seq(lower,upper,l=20))")
in order to do that I define
lower <- input$range[1]
upper <- input$range[2]
in reactive
and renderPrint
sections But I have an error and I donot know where I made a mistake in ui section or server section. I used
sliderInput("range", "Smooth Parameter range:",min = 0, max = 1000, value = c(0,1000)))
to defind the range. I have this error object 'lower' not found. Any advice?
library(shiny)
library(quantreg)
library(quantregGrowth)
ui = tagList(
tags$head(tags$style(HTML("body{ background: aliceblue; }"))),
navbarPage(title="",
tabPanel("Data Import",
sidebarLayout(sidebarPanel( fileInput("file","Upload your CSV",multiple = FALSE),
tags$hr(),
h5(helpText("Select the read.table parameters below")),
checkboxInput(inputId = 'header', label = 'Header', value = FALSE),
checkboxInput(inputId = "stringAsFactors", "StringAsFactors", FALSE),
radioButtons(inputId = 'sep', label = 'Separator',
choices = c(Comma=',',Semicolon=';',Tab='\t', Space=''), selected = ',')
),
mainPanel(uiOutput("tb1"))
) ),
tabPanel("95% Continious Reference Intervals",
sidebarLayout(sidebarPanel(
uiOutput("model_select"),
uiOutput("var1_select"),
uiOutput("rest_var_select"),
sliderInput("range", "Smooth Parameter range:",min = 0, max = 1000, value = c(0,1000))
),
mainPanel( helpText("Selected variables and Fitted values"),
verbatimTextOutput("other_val_show")))),
tabPanel("Model Summary", verbatimTextOutput("summary")),
tabPanel("Scatterplot", plotOutput("scatterplot"))#, # Plot
,inverse = TRUE,position="static-top",theme ="bootstrap.css"))
server<-function(input,output) { data <- reactive({
lower <- input$range[1]
upper <- input$range[2]
file1 <- input$file
if(is.null(file1)){return()}
read.table(file=file1$datapath, sep=input$sep, header = input$header, stringsAsFactors = input$stringAsFactors)
})
output$table <- renderTable({
if(is.null(data())){return ()}
data()
})
output$tb1 <- renderUI({
tableOutput("table")
})
#output$model_select<-renderUI({
#selectInput("modelselect","Select Algo",choices = c("Reference Interval"="Model")) #Logistic_reg
#})
output$var1_select<-renderUI({
selectInput("ind_var_select","Select Independent Variable", choices =as.list(names(data())),multiple = FALSE)
})
output$rest_var_select<-renderUI({
checkboxGroupInput("other_var_select","Select Dependent Variable",choices =as.list(names(data()))) #Select other Var
})
output$other_val_show<-renderPrint({
lower <- input$range[1]
upper <- input$range[2]
input$other_var_select
input$ind_var_select
f<-data()
library(caret)
library(quantregGrowth)
dep_vars <- paste0(input$ind_var_select, collapse = "+")
after_tilde <- paste0("ps(", dep_vars, ", lambda = seq(lower,upper,l=20))")
dyn_string <- paste0(input$other_var_select, " ~ ", after_tilde)
Model<-quantregGrowth::gcrq(as.formula(dyn_string),tau=c(0.025,0.975), data=f)
temp <- data.frame(Model$fitted)
growthData_b <- cbind(f, temp)
print(growthData_b)
})
}
shinyApp(ui=ui,server=server)