Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将checkboxGroupInput对象转换为向量_R_Shiny_Rpython - Fatal编程技术网

将checkboxGroupInput对象转换为向量

将checkboxGroupInput对象转换为向量,r,shiny,rpython,R,Shiny,Rpython,在长时间搜索可能的答案后,我仍然无法从用户输入(特别是checkboxGroupInput)中创建字符向量 我的最终目的是使用RPython将用户选择的条目从checkboxGroupInput传递到python列表中,以便进一步处理。然而,即使使用toString,我也只能一个字符一个字符地完成,而不是整个单词。我读过建议使用双括号索引的帖子。实际上,在server.r中使用单括号和/或toString see注释掉的命令时,我并没有看到任何结果上的差异。在这两种情况下,我最终都会在pytho

在长时间搜索可能的答案后,我仍然无法从用户输入(特别是checkboxGroupInput)中创建字符向量

我的最终目的是使用RPython将用户选择的条目从checkboxGroupInput传递到python列表中,以便进一步处理。然而,即使使用toString,我也只能一个字符一个字符地完成,而不是整个单词。我读过建议使用双括号索引的帖子。实际上,在server.r中使用单括号和/或toString see注释掉的命令时,我并没有看到任何结果上的差异。在这两种情况下,我最终都会在python中使用像L、o、n、d、o、n这样的变量,而不仅仅是London

# server.R
library(shiny)
library(rPython)
copy2  <- function(test) {
    python.exec("locations = []")
    for (i in 1:length(test)) {
        python.assign("temp",toString(test[[i]]))
#       python.assign("temp",test[i])
        python.exec("locations.extend(temp)")
    }
    python.exec("print locations")
}

shinyServer(function(input, output) {
    output$chosen <- renderPrint({
        string <- copy2(input$checkGroup)
    })
  }
)


# ui.r    
library(shiny)
library(rPython)

locations <- c("London", "Paris", "Munich")

shinyUI(pageWithSidebar(
    headerPanel(
      "Map",
  ),
    sidebarPanel(
        checkboxGroupInput("checkGroup", 
            label = h3("Select Locations:"), 
            locations,)
    ),
    mainPanel(
    h3('Main Panel text'),
    p('Selected Locations:'),
    verbatimTextOutput("chosen")
    )
))   
将R对象的内容从checkboxGroupInput中选择的值传输到R向量或Python列表中的最佳方法是什么


谢谢你的建议。

问题出在你的Python代码中

您必须理解list.append和list.extend之间的区别

>>> locations = []
>>> locations.append("London")
>>> locations
['London']
>>> locations = []
>>> locations.append("London")
>>> locations
['London']