Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R-重置渲染文本_R_Shiny_Shinyjs - Fatal编程技术网

R-重置渲染文本

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

在下面的代码中,目标是在单击按钮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(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")
  })

}

服务器太棒了!这正是我想要的行为。