考えられる答えを長い間探した後、ユーザー入力 (特にcheckboxGroupInput) から文字ベクトルを作成できません。
私の最終的な目的は、ユーザーが選択したエントリをcheckboxGroupInputからPythonリスト(RPythonを使用)に渡して、さらに処理することです。ただし、toStringを使用している場合でも、単語全体ではなく、「文字ごと」にしかできません。二重括弧のインデックス作成を提案する投稿を読んで、Shiny で複数のチェックボックスの値を取得しています。実際、一重括弧や toString を使用しても、結果に違いは見られませんでした (server.r のコメントアウトされたコマンドを参照)。どちらの方法でも、「London」だけでなく、「L」、「o」、「n」、「d」、「o」、「n」などの変数をPythonで使用することになります。
# 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 Shiny オブジェクトの内容 (checkboxGroupInput から選択された値) を R ベクトルまたは Python リストに単純に転送する最良の方法は何でしょうか?
アドバイスありがとう。