I use the fileInput Browse button as a tool to refresh the shinyapp including the variable input$search. The output$table <- DT::renderDataTable({}) displays the table that is loaded from fileInput Browse, and then subtable is displayed by inputting key word into the inside search box. However, when the second file is loaded, the value of variable input$search is kept. I want to change the input$search to NULL or empty string or initial status. Below is my codes.
shinyUI(fluidPage(
shinyjs::useShinyjs(),
theme = shinytheme("spacelab"),
sidebarLayout(
sidebarPanel(
p(strong('Inputs')),
hr(),
fileInput("file1", "Upload clonotype input file", accept = ".csv")
),
mainPanel(
tabsetPanel(
id = "tabs",
tabPanel(title = "table",tags$br(),DT::dataTableOutput("table")),
)
)
)
))
shinyServer(function(input, output) {
datasetInput <- reactive({
file <- input$file1
ext <- tools::file_ext(file$datapath)
req(file)
validate(need(ext == "csv", "Please upload a csv file"))
read.csv(file$datapath, header = T, sep=',',stringsAsFactors = F)
})
output$table <- DT::renderDataTable({
mytbl = datasetInput()
DT::datatable(
mytbl,
callback = JS(
"table.on( 'search.dt', function () {",
"Shiny.setInputValue( 'search', table.search() );",
"} );"
),
rownames=FALSE,
)
})
})
# Run the application
shinyApp(ui = shinyUI, server = shinyServer)