Ui.R file is
ui<-fluidPage(
fluidRow(
tags$h5("Inputs",style="color:red"),
tags$em(column(2,selectInput("table Type","Table",choices = c("TableA","TableB","TableC"))),style="color:blue"),
tags$em(column(2,uiOutput("Part ID")),style="color:blue")
),
fluidRow(
tags$em(tags$h5("Parts Data",style="color:red")),
column(5,dataTableOutput("table1"))
)
)
The server.R file is
server <- function(input, output,session) {
observe({
if(input$`table Type`=="A"){
output$`Part ID`<-renderUI(selectInput("PartsID","Part ID",choices = TableA$PartsID))
Table1<-subset(Input_Table,PartsID==input$PartsID)
output$table1<-renderDataTable(table1)
}
})
observe({
if(input$`table Type`=="B"){
output$`Part ID`<-renderUI(selectInput("PartsID","Part ID",choices = TableB$PartsID))
Table2<-subset(TableB,PartsID==input$PartsID)
output$table1<-renderDataTable(Table2)
}
})
observe({
if(input$`table Type`=="C"){
output$`Part ID`<-renderUI(selectInput("PartsID","Part ID",choices = TableC$PartsID))
Table3<-subset(TableC,PartsID==input$PartsID)
output$table1<-renderDataTable(Table3)
}
})
}
Global.R file contains
library(shiny)
library(DT)
library(openxlsx)
library(dplyr)
TableA<-read.xlsx("…\\Table.xlsx,sheet"=1,startRow=1,colnames=TRUE)
TableB<-read.xlsx("…\\Table.xlsx",sheet=2,startRow=1,colnames=TRUE)
TableC<-read.xlsx("…\\Table.xlsx,sheet"=3,startRow=1,colnames=TRUE)
The problem I am facing is that on selecting PartID from input the output table is generated for 1 second and then PartID gets reset to initial value.
I have tried updating the server.R file
instead renderUi I have used updateselectinput.
changed Observe() to ObserveEvent(input$Part ID
{...})
used isolate() different places.
Like
output$`Part ID`<-renderUI(isolate(selectInput("PartsID","Part ID",choices = TableC$PartsID)) )
or,
observe({ isolate({
if(input$`table Type`=="C"){
output$`Part ID`<-renderUI(selectInput("PartsID","Part ID",choices = TableC$PartsID))
Table3<-subset(TableC,PartsID==input$PartsID)
output$table1<-renderDataTable(Table3)
}
})
# Here, Part ID input do not reset but the "table is not updated either".
and everywhere in the middle
What, am I doing wrong.
I am still learning Observe(), ObserveEvent() & isolate() functions, they are pretty new for me.
Thanking you for your time and concern.