Could you please help me adjust the two tabPanel
that I inserted in my code below? I inserted two and none of them are showing, I don't know what I'm wrong with. Every help is welcome. Thanks in advance. I inserted a executable code below
library(shiny)
library(shinythemes)
library(dplyr)
function.test<-function(){
df1 <- structure(
list(date= c("2021-06-28","2021-06-28","2021-06-28"),
Category = c("ABC","ABC","ABC"),
Week= c("Wednesday","Wednesday","Wednesday"),
DR1 = c(4,1,0),
DR01 = c(4,1,0), DR02= c(4,2,0),DR03= c(9,5,0),
DR04 = c(5,4,0),DR05 = c(5,4,0),DR06 = c(5,4,0),DR07 = c(5,4,0),DR08 = c(5,4,0)),
class = "data.frame", row.names = c(NA, -3L))
return(df1)
}
ui <- fluidPage(
ui <- shiny::navbarPage(theme = shinytheme("flatly"), collapsible = TRUE,
br(),
tabPanel("First Panel",
fluidPage(
fluidRow(
br(), br(),
column(4, "",
wellPanel(
uiOutput("date"),
uiOutput("mycode")
),
wellPanel(
conditionalPanel(
condition = "output.mycode",
actionButton("reset", "Reset")
)
)
),
column(8, "",
tabsetPanel(
tabPanel("Output1", plotOutput("graph",width = "100%", height = "600"),
tabPanel("Output2",uiOutput('daterange')),
tabPanel("Output3")
)
)
))
)
)))
server <- function(input, output,session) {
data <- reactive(function.test())
output$date <- renderUI({
req(data())
all_dates <- seq(as.Date('2021-01-01'), as.Date('2021-01-15'), by = "day")
disabled <- as.Date(setdiff(all_dates, as.Date(data()$date2)), origin = "1970-01-01")
dateInput(input = "date2",
label = h4("Data"),
min = min(data()$date2),
max = max(data()$date2),
value = NA,
format = "dd-mm-yyyy",
datesdisabled = disabled)
})
output$daterange <- renderUI({
tagList(dateRangeInput("daterange1", "",
start = min(data()$date),
end = max(data()$date),
min = min(data()$date),
max = max(data()$date),
format = "dd-mm-yyyy"))
})
observeEvent(input$reset, {
req(input$date2)
df1 <- data()
my$plot <- NULL
updateDateInput(session, 'date2', value = NA)
updateSelectInput(session, 'code', h4("Category"),choices= unique(df1$Category), selected=character(0))
})
}
shinyApp(ui = ui, server = server)
Example:
CodePudding user response:
It seems like the feedback from @Silentdevildoll would support your needs. Plus your have called fluidPage() two times and navbarPage() within the UI. Additionally, you have assigned the object "ui" twice
library(shiny)
library(shinythemes)
library(dplyr)
function.test<-function(){
df1 <- structure(
list(date= c("2021-06-28","2021-06-28","2021-06-28"),
Category = c("ABC","ABC","ABC"),
Week= c("Wednesday","Wednesday","Wednesday"),
DR1 = c(4,1,0),
DR01 = c(4,1,0), DR02= c(4,2,0),DR03= c(9,5,0),
DR04 = c(5,4,0),DR05 = c(5,4,0),DR06 = c(5,4,0),DR07 = c(5,4,0),DR08 = c(5,4,0)),
class = "data.frame", row.names = c(NA, -3L))
return(df1)
}
ui <-
shiny::navbarPage(theme = shinytheme("flatly"),
collapsible = TRUE,
br(),
tabPanel(title = "First Panel",
fluidRow(
br(),
br(),
column(width = 4, "",
wellPanel(
uiOutput("date"),
uiOutput("mycode")
), #close wellPanel
wellPanel(
conditionalPanel(
condition = "output.mycode",
actionButton("reset", "Reset")
) #close conditionalPanel
) #close wellPanel
), #close column
column(width = 8, "",
tabsetPanel(
tabPanel("Output1",
plotOutput("graph", width = "100%", height = "600"),
tabsetPanel(
tabPanel("Output2",
uiOutput('daterange')),
tabPanel("Output3")
) # close tabsetPanel
) #close tabPanel
) # close tabsetPanel
) #close column
) #close fluidRow
) #close tabPanel
) #close NavPage
server <- function(input, output,session) {
data <- reactive(function.test())
output$date <- renderUI({
req(data())
all_dates <- seq(as.Date('2021-01-01'), as.Date('2021-01-15'), by = "day")
disabled <- as.Date(setdiff(all_dates, as.Date(data()$date2)), origin = "1970-01-01")
dateInput(input = "date2",
label = h4("Data"),
min = min(data()$date2),
max = max(data()$date2),
value = NA,
format = "dd-mm-yyyy",
datesdisabled = disabled)
})
output$daterange <- renderUI({
tagList(dateRangeInput("daterange1", "",
start = min(data()$date),
end = max(data()$date),
min = min(data()$date),
max = max(data()$date),
format = "dd-mm-yyyy"))
})
observeEvent(input$reset, {
req(input$date2)
df1 <- data()
my$plot <- NULL
updateDateInput(session, 'date2', value = NA)
updateSelectInput(session, 'code', h4("Category"),choices= unique(df1$Category), selected=character(0))
})
}
shinyApp(ui = ui, server = server)
CodePudding user response:
Try this
column(8, "",
tabsetPanel(
tabPanel("Output1", plotOutput("graph",width = "100%", height = "600")),
tabPanel("Output2",uiOutput('daterange')),
tabPanel("Output3")
)
)