R-重置渲染文本
在下面的代码中,目标是在单击按钮1后根据所选值重置textoutput的值:R-重置渲染文本,r,shiny,shinyjs,R,Shiny,Shinyjs,在下面的代码中,目标是在单击按钮1后根据所选值重置textoutput的值: library(shiny) library(shinythemes) library(DT, warn.conflicts = FALSE) #shiny also uses: dataTableOutput & renderDataTable library(shinyjs) library(shinyBS) #for tooltips on an input or output. library(html
library(shiny)
library(shinythemes)
library(DT, warn.conflicts = FALSE) #shiny also uses: dataTableOutput & renderDataTable
library(shinyjs)
library(shinyBS) #for tooltips on an input or output.
library(htmltools)
ui <- fluidPage(theme = shinytheme("lumen"),
useShinyjs(),
titlePanel(""),
selectInput(
inputId = "test1",
label = strong("pick something"),
choices = c("a - button shows", "b - button hidden", "c - button hidden"),
selected = "b",
selectize = TRUE,
width = "175px",
multiple = FALSE),
hidden(actionButton("button1", "Click Me")),
htmlOutput(outputId = "textoutput")
)
server <- function(input, output, session) {
output$textoutput <- renderText({
if (input$test1 == "a - button shows"){
print("a")
shinyjs::show("button1")
paste("<i><span style='color:blue'>You chose a. You should click the button.</span></i>")
}
else if (input$test1 == "b - button hidden"){
print("b")
shinyjs::hide("button1")
paste("<i><span style='color:green'>You chose b. No button.</span></i>")
}
else {
shinyjs::hide("button1")
print("c")
paste("<i><span style='color:orange'>The button is hidden.</span></i>")
}
})
observeEvent(input$button1,{
print(input$test1)
output$textoutput <- renderText({ paste("<i><span style='color:purple'>You clicked the button.</span></i>")})
shinyjs::hide("button1")
})
}
# Create Shiny object
shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(shinythemes)
库(DT,warn.conflicts=FALSE)#shiny还使用:dataTableOutput和renderDataTable
图书馆(shinyjs)
库(shinyBS)#用于输入或输出的工具提示。
图书馆(htmltools)
ui我认为您需要一个基于输入中的各种更改进行更新的输出$textoutput
可能反应性值可能包含您希望呈现的消息。例如:
server <- function(input, output, session) {
msg_txt <- reactiveVal("")
observe({
if (input$test1 == "a - button shows"){
print("a")
shinyjs::show("button1")
msg_txt("<i><span style='color:blue'>You chose a. You should click the button.</span></i>")
}
else if (input$test1 == "b - button hidden"){
print("b")
shinyjs::hide("button1")
msg_txt("<i><span style='color:green'>You chose b. No button.</span></i>")
}
else {
shinyjs::hide("button1")
print("c")
msg_txt("<i><span style='color:orange'>The button is hidden.</span></i>")
}
})
output$textoutput <- renderText({ msg_txt() })
observeEvent(input$button1,{
print(input$test1)
msg_txt("<i><span style='color:purple'>You clicked the button.</span></i>")
shinyjs::hide("button1")
})
}
服务器太棒了!这正是我想要的行为。