reset on file load

7 views
Skip to first unread message

Wilbert Heeringa

unread,
May 22, 2017, 12:07:21 PM5/22/17
to Shiny - Web Framework for R
Dear all,

I wrote an app with two tabs, one tab for loading a file, a second for showing a graph. Each time I switch from the second tab back  to the first tab, I would have the app to reset the page and then give the possibility to load a file again. What I tried was this:

------------------------------------------

library(shiny)
library(shinyBS)
library(shinyjs)
library(V8)
library(readxl)

jsResetCode <- "shinyjs.reset = function() {history.go(0)}"

ui <- fluidPage(
  useShinyjs(),
  extendShinyjs(text = jsResetCode),
 
  navbarPage(
    id = "navBar",
    title=NULL,

    tabPanel(
      title = "Load file",
      fileInput('vowelFile', 'Choose xlsx file', accept = c(".xlsx"), width="100%"),
      textOutput('checkFormat')
    ),

    tabPanel(
      title = "Plot tab",
      plotOutput("histPlot")
    )
  )
)

server <- function(input, output)
{
  observeEvent(input$navBar,{
    if (input$navBar==" Load file")
    {
      js$reset()
    }
  })

  output$histPlot <- renderPlot({
    hist(x=runif(100,0,50))
  }) 
}
 
shinyApp(ui = ui, server = server)

------------------------------------

What happens, however, it that the program stays continuously resetting. I do not understand this, with 'observeEvent(input$navBar'  I thought the program would reset only if I switch panels, but if I am back in the first panel without switching, I would have expected the program to reset just one time. How can this be solved?

Best regards, Wilbert



Reply all
Reply to author
Forward
0 new messages