我试图弄清楚如何使 Shiny R 包中的 renderPlot 函数中的“height”变量从 renderPlot() 内部接收变量。这是我在 server.R 中的代码:
shinyServer(function(input, output) {
output$contents <- renderPlot({
file<-input$file #a CSV file is uploaded
file<-with(file,
aggregate(file[, input$metricIn],
by=list(period=day,
dimension1=file[, input$dimension1In],
dimension2=file[, input$dimension2In]),
FUN = input$funIn, na.rm=TRUE))
#input$dimension1In is column name from file
#input$dimension2In is column name from file
#count of facets in the plot to calculate height in renderPlot height argument
facetCount<<-as.numeric(length(unique(file[, input$dimension1In]))) * 100
plot<-reactive({
g<-ggplot(data = file, aes_string(x=input$dimension2In,
y=input$metricIn, fill=period))
plot<-g + geom_bar(stat="identity", position=position_dodge()) +
facet_wrap(as.formula(paste("~", input$dimension1In)),
scales = "free", …Run Code Online (Sandbox Code Playgroud) 我正在编写一个函数createFile来在目录中创建一个文件,除非它已经存在。我正在使用 Node.js 本机fs包来执行所有文件操作。我想让我的函数异步,所以我将所有fs函数都封装在 promise 中:
function writeFilePromise(writePath, textContent) {
return new Promise((resolve, reject) => {
fs.writeFile(writePath, textContent, (err) => {
reject();
});
resolve();
});
}
function mkDirPromise(dir) {
return new Promise(((resolve, reject) => {
fs.mkdir(path.join(constants.FILES_STORAGE_DIR, dir), (err) => {
reject(err);
});
resolve();
}));
}
Run Code Online (Sandbox Code Playgroud)
然后我还想包装fs.existsSync在承诺中以完成我的功能,但包装它会导致偶尔的错误行为,即,如果文件目录不存在而我想创建一个目录,则该目录将被创建为空而没有文件. 通过调试,我发现只有同步fs.existsSync才能始终工作。这是函数代码:
function createFile(dir, fileName, httpMethod, textContent) {
return new Promise(((resolve, reject) => {
const searchPath = path.join(ROOT_DIR, dir, fileName);
if (httpMethod === POST …Run Code Online (Sandbox Code Playgroud)