タイトルはかなり自明です。以下は問題を再現する簡単な例です。私が欲しいのは、ボタンがクリックされたときにボタンをアプリケーションのtextInputボックスに追加するラベルを付ける文字(a-z)です。Shiny AppでactionButton値を取得し、それに応じてtextInputを更新する
実際のアプリケーションでは、ボタンにラベルを付けることができる単語の数は実質的に無限であるため、文字のベクトル(p1)から文字の値を引き出すことはできません。ボタンラベル(value1)に渡される実際の値を取得する必要があります。
今、(HTML?)コードを取得しています。私が試してみました
注:
Capture label of actionButton in Shiny app
と
Capture the label of an actionButton once it is clicked
、彼らは私が近づく助けながら、彼らは現在の問題を解決しません。
library(shiny)
shinyUI(fluidPage(
# Application title
titlePanel("Letter Predictor"),
# Sidebar with action button
sidebarLayout(
sidebarPanel(
actionButton("word1", label = textOutput("value1"))
),
# Text entry box
mainPanel(
textInput(inputId = "text", label = h3("Text input"), value = "Enter a number (1-26)"),
hr()
)
)
)
)
shinyServer(function(input, output, session) {
# Letter prediction function to be used in Shiny Application
predictalg <- function(userinput, predictor, predicted){
pred <- predicted[which(predictor == userinput)]
return(pred)
}
# Vectors for making predictions
p1 <- letters
p2 <- seq_along(letters)
# Prediction function applied
value1 <- reactive({
predictalg(userinput = { trimws(input$text) },
predictor = p2,
predicted = p1)
})
output$value1 <- value1
# Register button click and (ideally) pass label (value1) to updateTextInput
observeEvent(input$word1, {
name <- paste(input$text, textOutput("value1"))#PROBLEM WITH value1
updateTextInput(session, "text", value = name)
})
})
私は光り輝く初心者です。私は立ち往生しています。どんな助けもありがとう!ミハルMajkaパー
これは 'textOutput(" value1 ")'があるため、HTMLコードを取得します。 'name < - paste(input $ text、value1())'を次のように変更すると、(おそらく)あなたが望むものが得られます。 –
これはうまくいくようです。ありがとうございました! – davo1979