Hi I would appreciate your help. I have the attached code. I import an excel data file and read the data. I have a renderUi command which by selectInput, reads the names of the inserted table and plots the relative columns of the data table.
When I run the code and I select the ParameterName_time and ParameterName ( which are the x and y parts of the plot ) , I can see the plot for just half a second but then it dissapears and the choices are back in the original state.
It looks like it is working but can not store the result. Maybe I need to use the updateselectInput command or it is something with the reactivity of hte inputs or the plot. please help !
# Define server function
server <- function(input,output,session) {[enter image description here][1]
Excel <- reactive({ # DATA IMPORT ------------------------------------------
inFile <- input$Excel
if (is.null(inFile)) { return(NULL) }
dataFile <- read_excel(inFile$datapath,sheet=1)
return(dataFile)
})
RV <- reactiveValues(Excel = data.frame())
output$Table_Of_Data = DT::renderDataTable({ # DATA TABLE ------------------------------------------
RV$Excel<-Excel()
},options = list(scrollX = TRUE))
# if (input$submitbutton_Show_Table>0){
# }
output$summary <- renderPrint({ # Summary of DATA TABLE ------------------------------------------
dataset <- Excel()
summary(dataset)
})
# RValsl <- reactive(input$NumberOfDates_L )
# RValsr<- reactive(input$NumberOfDates_R )
output$timeDataSetNumber <- renderUI({
fluidRow(
numericInput(inputId = "NumberOfDates_L", # INPUT PARAMETER
label = "Number Of Different Time Data Sets (Left Side):",
value = 1 ,
min = 1,
),
numericInput(inputId = "NumberOfDates_R", # INPUT PARAMETER
label = "Number Of Different Time Data Sets (Right Side):",
value = 1 ,
min = 1,
)
)
})
output$Plotoutput <- renderPlot({
n<-input$NumberOfDates_L
output$tabsets <- renderUI({
Panels <- lapply(1:n, function(number){
tabPanel(paste0("Set #", number),
fluidRow(
selectInput("ParameterName_time","Select the Date vector for this entry",names(RV$Excel),multiple = TRUE ),
selectInput("ParameterName", "Select the KPIs for this entry:", names(RV$Excel) ,multiple = TRUE ),
),
)
})
do.call(tabsetPanel,Panels)
})
#============
k<-input$NumberOfDates_R
output$tabsets_R <- renderUI({
Panels_R <- lapply(1:k, function(number){
tabPanel(paste0("Set #", number),
fluidRow(
selectInput("ParameterName_time_R","Select the Date vector for this entry",names(RV$Excel)),
selectInput("ParameterName_R", "Select the KPIs for this entry:",names(RV$Excel),multiple = TRUE),
),
)
})
do.call(tabsetPanel,Panels_R)
})
Excel<-RV$Excel ##########################################################
###############################
###################################################
# if (input$submitbutton>0){
source(file = "path................TimeVector.R")
TVmean=TimeVector(input$Starting_Date,input$Ending_Date,input$Time)[,1]
TV1=TimeVector(input$Starting_Date,input$Ending_Date,input$Time)[,2]
TV2=TimeVector(input$Starting_Date,input$Ending_Date,input$Time)[,3]
#====================================================
# Value<- Excel %>% select(c(input$ParameterName))
source(file = "C:/Users/AntoniosTriantos/OneDrive - ClearWELL Oilfield Solutions/Desktop/App/Scripts/ReducedParameter.R")
# Left Side of the plot
kpi_entries=length(input$ParameterName)
# kpi_Time_entries=length(input$ParameterName_time)
KPITable=c(TVmean)
for ( i in 1:kpi_entries){
# for ( j in 1:kpi_Time_entries){
AV_Prop_Value_reduced=ReducedParameter(input$ParameterName_time[1],input$ParameterName[i],Excel,TV1,TV2)
KPITable=(cbind.data.frame(KPITable,AV_Prop_Value_reduced ))
}
# }
# Right Side of the plot
if (length(input$ParameterName_R)>0){
kpi_entries_R=length(input$ParameterName_R)
KPITable_R=c(TVmean)
for ( i in 1:kpi_entries_R){
AV_Prop_Value_reduced_R=ReducedParameter(input$ParameterName_time_R[1],input$ParameterName_R[i],Excel,TV1,TV2)
KPITable_R=(cbind.data.frame(KPITable_R,AV_Prop_Value_reduced_R ))
}
}
#====================================================
source(file = "path................Plot.R")
Plot<-PlotFunction(TVmean,AV_Prop_Value_reduced,kpi_entries,KPITable,input$ParameterName_R,kpi_entries_R,KPITable_R)
# }
})
}
ui <- fluidPage(theme = shinytheme("cerulean"),
navbarPage(
# theme = "cerulean", # <--- To use a theme, uncomment this
"ClearKPI",
tabPanel("Navbar 1",
sidebarPanel(wellPanel(fileInput('Excel', 'Choose XLSX File',
accept=c('sheetName', 'header'), multiple=FALSE))),
# actionButton("submitbutton_Show_Table","Show table",class ="btn btn-primary"),
h1("Excel Data"),
DT::dataTableOutput("Table_Of_Data"), # SHOW DATA TABLE
# Output: Verbatim text for data summary ----
verbatimTextOutput("summary"),
headerPanel("KPI Entry Point") , # INPUT KPIs vs Dates PARAMETER
uiOutput("timeDataSetNumber") ,
mainPanel(h2("Left side of the plot - Input:"),
uiOutput("tabsets")),
mainPanel(h2("Right side of the plot - Input:"),
uiOutput("tabsets_R")),
headerPanel("Edit Plot") , # INPUT KPIs vs Dates PARAMETER
numericInput(inputId = "Time", # INPUT PARAMETER
label = "Number of Hours to round:",
value = 4),
dateInput(
inputId="Starting_Date" ,
label="Starting Date:",
value = "2022-02-08",
min = NULL,
max = NULL,
format = "yyyy-mm-dd",
startview = "year",
weekstart = 0,
language = "en",
width = NULL,
autoclose = TRUE,
datesdisabled = NULL,
daysofweekdisabled = NULL),
dateInput( # INPUT PARAMETER
inputId="Ending_Date" ,
label="Ending Date:",
value = "2022-06-27",
min = NULL,
max = NULL,
format = "yyyy-mm-dd",
startview = "year",
weekstart = 0,
language = "en",
width = NULL,
autoclose = TRUE,
datesdisabled = NULL,
daysofweekdisabled = NULL),
# actionButton("submitbutton","Submit",class ="btn btn-primary"),
mainPanel(h2("Plot:"),
plotOutput(outputId = "Plotoutput", width = 1250 , height = 800) # OUTPUT PARAMETER
), # mainPanel
)
)
)
rm(list = ls())
source(file = "path................UI.R")
source(file = "path................SERVER.R")
# Create Shiny object
shinyApp(ui = ui, server = server)