Appear conditionalPanel after pressing the reset button on shiny

前端 未结 2 394
南方客
南方客 2020-12-21 15:17

Friends, could you help me with the following problem: The executable code is working correctly. I am using the database via fileInput. It\'s working. I insert the functiona

相关标签:
2条回答
  • 2020-12-21 15:44

    This is not ideal, but something you can try. This is a smaller (reproducible) example to test. Your question might get more attention if it is reduced to what is needed to reproduce the problem.

    You can add another reactiveValues flag (in this case called clear) that tracks whether data has been loaded or not, and use that.

    I looked around for good solutions on resetting fileInput but found mostly work arounds. In this case, when you hit reset, the fileInput still looks the same, which is not desirable.

    However, when you hit reset the conditionalPanel should be response through output$fileUploaded.

    library(shiny)
    library(shinythemes)
    library(readxl)
    
    df<-structure(list(Properties = c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35), 
                       Latitude = c(-23.8, -23.8, -23.9, -23.9, -23.9,  -23.9, -23.9, -23.9, -23.9, -23.9, -23.9, -23.9, -23.9, -23.9, -23.9, -23.9, -23.9, -23.9, -23.9,-23.9,-23.9,-23.9,-23.9,-23.9,-23.9,-23.9,-23.9,-23.9,-23.9,-23.9,-23.9,-23.9,-23.9,-23.9,-23.9), 
                       Longitude = c(-49.6, -49.6, -49.6, -49.6, -49.6, -49.6, -49.6, -49.6, -49.6, -49.6, -49.7, -49.7, -49.7, -49.7, -49.7, -49.6, -49.6, -49.6, -49.6,-49.6,-49.6,-49.6,-49.6,-49.6,-49.6,-49.6,-49.6,-49.6,-49.6,-49.6,-49.6,-49.6,-49.6,-49.6,-49.6), 
                       Waste = c(526, 350, 526, 469, 285, 175, 175, 350, 350, 175, 350, 175, 175, 364, 175, 175, 350, 45.5, 54.6,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350)), 
                  class = "data.frame", row.names = c(NA, -35L))
    
    ui <- bootstrapPage(
      navbarPage(theme = shinytheme("flatly"), collapsible = TRUE,
                 "Cl", 
                 tabPanel("Solution",
                          fileInput("data", h3("Import excel")), 
                          sidebarLayout(
                            sidebarPanel(
                              radioButtons("filtro1", h3("Select properties"),
                                           choices = list("All properties" = 1, 
                                                          "Exclude properties" = 2),
                                           selected = 1),
    
                              tags$b(h5("(a) Choose other filters")),
                              tags$b(h5("(b) Choose clusters")),  
                              sliderInput("Slider", h5(""),
                                          min = 2, max = 8, value = 5),
                              conditionalPanel(
                                "output.fileUploaded == true",
                                tags$p(h3("Are you satisfied?")),
                                tags$b(h5("(a) Choose others filters")),
                                tags$b(h5("(b) Choose number of clusters"))),  
                              actionButton("reset", "Reset"),
                            ),
                            mainPanel(
                              tabsetPanel(      
                                tabPanel("Solution", plotOutput("ScatterPlot"))))
                          ))))
    
    server <- function(input, output, session) {
    
      v <- reactiveValues(df = NULL, clear = FALSE)
    
      observeEvent(input$reset, {
        v$df <- NULL
        v$clear <- FALSE
        updateRadioButtons(session, "Slider", selected = 5)
      })
    
      observeEvent(input$data, {
        v$df <- read_excel(input$data$datapath)
        v$clear <- TRUE
      })
    
      output$fileUploaded <- reactive({
        v$clear
      })
    
      outputOptions(output, "fileUploaded", suspendWhenHidden = FALSE)
    
      observe({
        updateSelectInput(session, 'select', choices=unique(df[df==input$Slider]))
      })
    
    }
    
    shinyApp(ui = ui, server = server)
    
    0 讨论(0)
  • 2020-12-21 15:48

    When the reset button is pressed, you set output$fileUploaded <-NULL, and the condition to show the panel conditionalPanel("output.fileUploaded == true", is not met anymore.

    You can possibly change the condition to conditionalPanel("output.fileUploaded == true | output.fileUploaded == NULL",

    0 讨论(0)
提交回复
热议问题