I'm creating a Shiny App that creates a ordered list starting from two inputs. The list is meant to order database objects depening on their relation.
Since I'm definining the possible inputs, I have inserted some if statements but that's not working (I get as a result the whole dataset instead of the portion I have selected).
I'm working with three main dataframes:
- Environments (EnvName, A1, A2, A3 as columns), the idea is that I need to complete the full schema name adding the environment and the env prefix changes depending on the area
- Relationships: list of all parent child relationships -Schemas: list of all the schema names, divided in different areas and part 1 and part 2 to allow the construction of the full name.
Code below
library(shiny)
library(shinydashboard)
library(dplyr)
ui <- shinyUI(pageWithSidebar(
headerPanel("Run Order List"),
sidebarPanel(
#declare 2 text inputs and submit button
selectInput("EnvName", "Environment:", c("Env")),
selectInput("Area", "Area:", c("A1", "A2","A3")),
actionButton(
inputId = "submit_loc",
label = "Submit")
),
mainPanel(
DT::dataTableOutput("RunOrder")
)
))
##
server <- shinyServer(function(input, output, session) {
observeEvent(
eventExpr = input[["submit_loc"]],
handlerExpr = {
input$EnvName
input$Area
#Loading the data
Relationships <- read.csv("myfile", header = TRUE, sep = ";")
Environments <- read.csv("myfile2", header = TRUE, sep = ";")
Schemas <- read.csv("myfile3", header = TRUE, sep = ";")
##CreatingListofSchemas
out <- reactive({
if (input$Area %in% "csa")
{
Environments <-subset(Environments, EnvName == input$EnvName)
Relevant_schemas <- subset(Schemas, Area == "A1")
Relevant_schemas $FullName <- paste(Relevant_schemas $Part1,Environment$A1,Relevant_schemas$Part2, sep="")
}
else if(input$Area %in% "A2"){
Environments <-subset(Environments, EnvName == input$EnvName)
Relevant_schemas <- subset(Schemas, Area == "A2")
Relevant_schemas$FullName <- paste(Environment$A2,Relevant_schemas$Part1, sep="")
}
else{
Environments <-subset(Environments, EnvName == input$EnvName)
Relevant_schemas <- subset(Schemas, Area == "A3")
Relevant_schemas $FullName <- paste(Relevant_schemas$Part1,Environment$A3,Csa_schemas$Part2, sep="")}
return(Relevant_schemas$FullName)
})
#Selecting environment
Relationships <- subset(Relationships, grepl(paste(Relevant_schemas$FullName, collapse = "|"), Relationships$ParentDB))
##a bunch of other stuff}
output$RunOrder = DT::renderDataTable({
RunOrder
})
})
})
##
shinyApp(ui = ui, server = server)
Aucun commentaire:
Enregistrer un commentaire