小编Yos*_*Yos的帖子

如何在 Shiny R 包的 renderPlot() 中使“高度”参数动态化

我试图弄清楚如何使 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)

r shiny

4
推荐指数
1
解决办法
3521
查看次数

为什么 node.js `fs.existsSync` 在包装在 promise 中时不能很好地工作?

我正在编写一个函数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)

javascript asynchronous fs node.js

2
推荐指数
1
解决办法
2940
查看次数

标签 统计

asynchronous ×1

fs ×1

javascript ×1

node.js ×1

r ×1

shiny ×1