R 为应用程序中的框设置默认文本值

R 为应用程序中的框设置默认文本值,r,shiny,R,Shiny,我得到了以下闪亮的应用程序: ## app.R ## library(shinydashboard) ui <- dashboardPage( dashboardHeader(title = "Basic dashboard"), dashboardSidebar(), dashboardBody( # Boxes need to be put in a row (or column) fluidRow( box(textOutput("butto

我得到了以下闪亮的应用程序:

## app.R ##
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title = "Basic dashboard"),
  dashboardSidebar(),
  dashboardBody(
    # Boxes need to be put in a row (or column)
    fluidRow(
      box(textOutput("button_outcome")),
      box(width = 2,  actionButton("runRF", "Predict"))
    )
  )
)


server <- function(input, output) {

  observeEvent(input$runRF, {
    #output$button_outcome = DT::renderDataTable({
    # titanic_train <- select(titanic_train, Pclass, Name)
    # head(titanic_train,5)
    #})
    output$button_outcome = renderPrint({ "foo" })
  })

}

shinyApp(ui, server)
##app.R##
图书馆(shinydashboard)

ui您可以在被动上下文之外呈现默认文本

server <- function(input, output) {

  output$button_outcome <- renderPrint("please press the button")

  observeEvent(input$runRF, {
    output$button_outcome = renderPrint({ "foo" })
  })

}

server通常,从观察者内部创建反应或输出是不好的做法。看见在这种情况下,我们可以将要显示的文本存储在一个名为
text\u to\u display
的reaciveVal中,我们可以从观察者那里更新它,有关它们如何工作的详细信息,请参阅。例如:

## app.R ##
library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title = "Basic dashboard"),
  dashboardSidebar(),
  dashboardBody(
    # Boxes need to be put in a row (or column)
    fluidRow(
      box(textOutput("button_outcome")),
      box(width = 2,  actionButton("runRF", "Predict"))
    )
  )
)


server <- function(input, output) {

  text_to_display <- reactiveVal('Please press the button.')

  observeEvent(input$runRF, {
    text_to_display('foo') # set new value to reactiveVal
  })

  output$button_outcome = renderPrint({  text_to_display() })

}

shinyApp(ui, server)
##app.R##
图书馆(闪亮)
图书馆(shinydashboard)
用户界面