我创建了一个Shiny应用程序,可以通过在输入字段中键入文本或按下向输入字段添加文本的各种按钮来添加文本。我已经在div中包含了输入字段,该div具有方向:ltr作为样式,因此当输入文本时,它会显示在右侧。但是,当使用updateTextInput和添加文本的按钮更新文本时,溢出文本最终会在右侧消失,因为它是左对齐的。在这方面,方向风格显然没有帮助,并且指定text-align:left也没有帮助。感谢任何帮助。谢谢。
strings <- c("on", "recommend", "tolerably", "my", "belonging", "or", "am", "mutual", "has", "cannot", "indeed", "now", "mutual", "jennings", "offended")
string.list = NULL
for (i in 1:3) {
rnum <- sample(1:length(strings), 1)
string.list <- c(string.list, strings[rnum])
}
string.list <- unlist(string.list)
# Define UI
ui = (fluidPage(align = "center",
div(textInput(inputId = "inputText", label = "Enter your text here:"), style="direction:ltr"),
#display dynamic UI
uiOutput("my_button", inline=TRUE),
uiOutput("button2", inline=TRUE),
uiOutput("button3", inline=TRUE),
p(verbatimTextOutput('text'), width = 200)
))
server = function(input, output, session){
#set up reactive text
text <- reactiveValues()
text$string.list <- string.list
#make dynamic button
output$my_button <- renderUI({
actionButton("action1", label = text$string.list[1])
})
output$button2 <- renderUI({
actionButton("action2", label = text$string.list[2])
})
output$button3 <- renderUI({
actionButton("action3", label = text$string.list[3])
})
output$text <- renderText({
text$text <- c(text$mainText, input$inputText)
})
observeEvent(input$action1, {
text$text <- paste(text$text, text$string.list[1])
output$text <- renderText({
text$text
})
updateTextInput(session = session, inputId = "inputText", value = text$text)
string.list = character(0)
for (i in 1:3) {
rnum <- sample(1:length(strings), 1)
string.list <- c(string.list, strings[rnum])
}
new.strings <- unlist(string.list)
text$string.list <- new.strings
})
observeEvent(input$action3, {
text$text <- paste(text$text, text$string.list[3])
output$text <- renderText({
text$text
})
updateTextInput(session = session, inputId = "inputText", value = text$text)
string.list = character(0)
for (i in 1:3) {
rnum <- sample(1:length(strings), 1)
string.list <- c(string.list, strings[rnum])
}
new.strings <- unlist(string.list)
text$string.list <- new.strings
})
observeEvent(input$action2, {
text$text <- paste(text$text, text$string.list[2])
output$text <- renderText({
text$text
})
updateTextInput(session = session, inputId = "inputText", value = text$text)
string.list = character(0)
for (i in 1:3) {
rnum <- sample(1:length(strings), 1)
string.list <- c(string.list, strings[rnum])
}
new.strings <- unlist(string.list)
text$string.list <- new.strings
})
}
runApp(list(ui = ui, server = server))