0
希望標題是相當自我解釋。下面是重現問題的簡單示例。我想要的是,一旦點擊按鈕,標註按鈕的字母(a-z)將被添加到應用中的textInput框中。捕捉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)
})
})
我是一個閃亮的新手,我卡住了。任何幫助,將不勝感激!
你得到的HTML代碼,因爲這是'textOutput(「value1」)'是什麼。如果你做了如下改變:'name < - paste(輸入$ text,value1())'你將(可能)得到你想要的。 –
這似乎工作。謝謝! – davo1979