I am creating an application where my first page contain two buttons and require different panels to open of click of each button. I have created one shiny script for buttons and two different shiny scripts for their actions. All the three are ready, but i am not getting how to integrate these. Please help as its important for my thesis work.
Code for Button Creation :
library("shinythemes")
ui <- fluidPage(theme = shinytheme("cosmo"),
h3(actionButton("runif", "For1"),align = "center"),
h3(actionButton("rnorm", "For2"),align = "center"),
hr(),
plotOutput("plot")
)
server <- function(input, output){
v <- reactiveValues(data = NULL)
observeEvent(input$runif, {
v$data <- runif(100)
})
observeEvent(input$rnorm, {
v$data <- rnorm(100)
})
output$plot <- renderPlot({
if (is.null(v$data)) return()
hist(v$data)
})
}
shinyApp(ui, server)
Code for Click Button DS1 :
Add a sidebar layout to the application
sidebarLayout(
# Add a sidebar panel around the text and inputs
sidebarPanel(
fileInput("file1", "Choose a csv dataset file",multiple= FALSE, accept = c(
"csv",
"comma-separated-values",
".csv"
),width = 500,buttonLabel = "select one file",placeholder = "Add a file ")
),
# Add a main panel around the plot and table
mainPanel(
tabsetPanel(
tabPanel("Dataset Overview",tableOutput("contents")),
tabPanel("Dataset Summary",tableOutput("datatypes")),
tabPanel("Data Analysis",plotOutput("missingValueStats"))
)
)
)
)
)
Define the server logic
server <- function(input, output) {
output$contents <- renderTable({
req(input$file1)
df <- read.csv(input$file1$datapath)
})
output$datatypes <- renderTable({
df <- read.csv(input$file1$datapath, stringsAsFactors = FALSE)
dataTypes<- sapply(df,class)
ColumnNames<- colnames(df)
table(ColumnNames,dataTypes)
})
output$missingValueStats <- renderPlot({
df <- read.csv(input$file1$datapath, header = T, na.strings = c("","NA"))
na_count <-sapply(df, function(y) sum(length(which(is.na(y)))))
na_count <- data.frame(colnames(df),na_count)
par(las=2)
par(mar=c(5,8,4,2)) # increase y-axis margin.
barplot(na_count[ ,2], names.arg = na_count[ ,1], horiz = TRUE)
})
output$duplicateValueStats <- renderText({
df <- read.csv(input$file1$datapath, header = T, na.strings = c("","NA"))
DuplicateRows<- aggregate(list(numdup=rep(1,nrow(df))), df, length)
aggregateSumOfDuplicates <- sum(DuplicateRows[DuplicateRows$numdup > 1,]$numdup, na.rm = TRUE)
DuplicateRows <- transform(DuplicateRows, duplicityCheck = ifelse(DuplicateRows$numdup>1,"dup","nondup"))
duplicateRowsActual <- nrow(DuplicateRows[DuplicateRows$duplicityCheck == "dup",])
NetDuplicates <- aggregateSumOfDuplicates- DuplicateRowsActual
TotalNumberOfRows<- nrow(df)
percentageOfDup <- (NetDuplicates/TotalNumberOfRows)*100
paste("The percentage of duplicates present within dataset: ",percentageOfDup,"%")
})
}
Run the application
shinyApp(ui = ui, server = server)
I am novice, may be i am not using correct functions or tags for my work.