小编Pat*_*her的帖子

R Shiny:处理数据表中的动作按钮

我有一个带有数据表的R Shiny应用程序.一列包含具有唯一ID的操作按钮.我想处理这些按钮的点击,但不幸的是,我的事件处理代码(一个简单的打印语句)永远不会被执行.看到这个自包含的例子(app.R):

library(shiny)
library(DT)

ui <- shinyUI(
    fluidPage(
        title = "DataTable with Buttons",
        fluidRow(
            column(
                width = 8,
                dataTableOutput("employees")
            )
        )
    )
)

server <- shinyServer(function(input, output) {
    df <- data.frame(
        name = c('Dilbert', 'Alice', 'Wally', 'Ashok', 'Dogbert'),
        motivation = c(62, 73, 3, 99, 52),
        stringsAsFactors = FALSE
    )
    fireButtons <- list()
    fireButtonIds <- list()
    for (r in rownames(df)) {
        id <- paste("fire_", r, sep = "")
        fireButtonIds[[r]] <- id
        button <- actionButton(id, label = "Fire")
        fireButtons[[r]] <- …
Run Code Online (Sandbox Code Playgroud)

r shiny

14
推荐指数
1
解决办法
6405
查看次数

转到模块:找出所需包的版本

我正在尝试Go模块.我的项目需要libarary golang.org/x/net/html,所以我定义了这个go.mod文件:

module github.com/patrickbucher/prettyprint

require golang.org/x/net/html
Run Code Online (Sandbox Code Playgroud)

并编写了这个演示程序来检查编译时是否加载了依赖项:

package main

import (
        "fmt"
        "log"
        "os"

        "golang.org/x/net/html"
)

func main() {
        doc, err := html.Parse(os.Stdin)
        if err != nil {
                log.Fatal(err)
        }
        fmt.Println(doc)
}
Run Code Online (Sandbox Code Playgroud)

当我运行go build时,我收到以下错误消息:

go: errors parsing go.mod:
~/prettyprint/go.mod:3: usage: require module/path v1.2.3
Run Code Online (Sandbox Code Playgroud)

显然,我错过了版本号.但是哪一个拿?我偶然发现了一篇名为Takig Go Modules for Spin的文章,在那里我找到了一个go.mod包含对golang.org/x包的引用的文件示例:

module github.com/davecheney/httpstat

require (
        github.com/fatih/color v1.5.0
        github.com/mattn/go-colorable v0.0.9
        github.com/mattn/go-isatty v0.0.3
        golang.org/x/net v0.0.0-20170922011244-0744d001aa84
        golang.org/x/sys v0.0.0-20170922123423-429f518978ab
        golang.org/x/text v0.0.0-20170915090833-1cbadb444a80
)
Run Code Online (Sandbox Code Playgroud)

作者正在使用版本字符串v0.0.0-20170922011244-0744d001aa84,包括semver indication v0.0.0,时间戳和看起来像git提交ID的东西.

我如何找出那些版本字符串?我猜想那些 …

go go-modules

7
推荐指数
4
解决办法
4663
查看次数

Rust:“sort_by”多个标准,详细模式匹配

我有Vector一些球员要按照以下标准进行排序:

  1. championships(降序)
  2. wins(降序)
  3. name(升序)

我在 Rust 中实现如下:

use std::cmp::Ordering;

#[derive(Debug)]
struct Player {
    name: String,
    championships: u8,
    wins: u8,
}

fn main() {
    let mut players = vec![
        Player {
            name: "Alice".to_string(),
            championships: 3,
            wins: 17,
        },
        Player {
            name: "Bob".to_string(),
            championships: 3,
            wins: 19,
        },
        Player {
            name: "Claire".to_string(),
            championships: 4,
            wins: 18,
        },
        Player {
            name: "Dan".to_string(),
            championships: 4,
            wins: 18,
        },
    ];
    players.sort_by(|a, b| match b.championships.cmp(&a.championships) {
        Ordering::Less => …
Run Code Online (Sandbox Code Playgroud)

sorting match rust

3
推荐指数
1
解决办法
153
查看次数

范围总和:奇怪的行为

Eloquent JavaScript第4章中,我在本章的末尾实现了一个练习,该练习需要编写两个函数:sumrange。我的解决方案工作正常:

console.log(sum(range(1, 10)));

function range(from, to, step = 1) {
    let numbers = [];
    for (let i = from; i <= to; i += step) {
        numbers.push(i);
    }
    return numbers;
}

function sum(numbers) {
    sum = 0;
    for (let x of numbers) {
        sum += x;
    }
    return sum;
}
Run Code Online (Sandbox Code Playgroud)

但是,当我有两次第一行时,出现错误:

console.log(sum(range(1, 10)));
console.log(sum(range(1, 10))); // additional line

function range(from, to, step = 1) {
    let numbers = [];
    for (let i = …
Run Code Online (Sandbox Code Playgroud)

javascript node.js

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

可以在使用 print 的示例中进行简化!和冲洗?

几天前,我通过阅读官方文档开始了 Rust 编程。现在,我试图通过阅读 Brian P. Hogan(The Pragmatic Programmers)的“程序员练习”一书来挑战我对 Rust 的理解。

第一个练习是编写一个程序,要求用户输入姓名并使用该姓名打印出问候语。输入、字符串连接和输出应该在三个不同的步骤中完成。

What is your name? Patrick
Hello, Patrick, nice to meet you.
Run Code Online (Sandbox Code Playgroud)

该名称将在与初始提示相同的行中输入。这是我的解决方案:

use std::io;
use std::io::Write;

fn main() {
    print!("What is your name? ");
    match io::stdout().flush() {
        Ok(_) => print!(""),
        Err(error) => println!("{}", error),
    }
    let mut name = String::new();
    match io::stdin().read_line(&mut name) {
        Ok(_) => {
            name = name.trim().to_string();
            if name.len() > 0 {
                let greeting = "Hello, ".to_string() + &name + &", nice to meet you!".to_string();
                println!("{}", …
Run Code Online (Sandbox Code Playgroud)

input flush rust output

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

Clojure:将 println 应用于多个字符串打乱输出

在 Clojure 1.11 中,我正在评估这个术语:

(apply println "foo\n" "bar\n" "baz\n")
Run Code Online (Sandbox Code Playgroud)

我期望以下输出:

foo
bar
baz
Run Code Online (Sandbox Code Playgroud)

但是,我得到了这个

foo
 bar
 b a z
Run Code Online (Sandbox Code Playgroud)

第一行是我需要的。第二行包含一个前导空格。第三行每个字母之前有一个多余的空格。

为什么会apply这样println,我怎样才能得到想要的输出?

clojure apply println

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

标签 统计

rust ×2

apply ×1

clojure ×1

flush ×1

go ×1

go-modules ×1

input ×1

javascript ×1

match ×1

node.js ×1

output ×1

println ×1

r ×1

shiny ×1

sorting ×1