I am trying to call my javascript code using my R code but I am encountering this error. "Error in : shinyjs: Error parsing the JavaScript file: ReferenceError: require is not defined. "
I have seen that the reason is
"This is because require() does not exist in the browser/client-side JavaScript." Client on node: Uncaught ReferenceError: require is not defined
I am really not familiar with client-side and server-side. I just need the javascript functions I created which calls a specific modules. Any idea how to do it?
In ui.R
ui <- fluidPage(
useShinyjs(),
extendShinyjs(script="js/getAppDetails.js"),
sidebarLayout(
sidebarPanel(
actionButton("analyze_reviews", label="Analyze", "js$getAppDetails('app_id')"),
),
mainPanel(
)
)
)
In server.R
server <- function(input, output, session) {
observeEvent(input$app_selection, {
invalidateLater(0, session)
output$app_id <- renderText({
app_detail$appId[1]
})
})
observeEvent(output$app_id, {
js$getAppDetails('app_id')
})
})
In getAppDetails.js
var json2csv = require('json2csv').Parser
var fs = require('fs')
var json = require('json')
shinyjs.getAppDetails = function getAppDetails (appId) {
// call some function to return data
const detailJson2csvParser = new json2csv({appFields})
const z = detailJson2csvParser.parse(data)
let app_detail = z.substring(z.search(/\n/), z.length)
fs.appendFile('AppDetail.csv', app_detail, function(status) {
if (status) throw status
console.log(`App Data of ${appId} successfully saved.`)
})
}).catch(function (e) {
console.log(e)
console.log('There was an error fetching the app data!')
})
}
I am getting this error:
Warning: Error in : shinyjs: Error parsing the JavaScript file: ReferenceError: require is not defined.