我怎样才能正确 link 我的 ui 和这个 Shiny 应用程序的服务器文件

How can I properly link my ui and server files for this Shiny app

我正在尝试组装一个闪亮的应用程序;这远远超出了我通常会做的事情。最初,我组合了一个接受三个输入的函数(coolFunction 下面):

  1. x - 一个字符串
  2. y - 从列表中取出的字符串
  3. t - 一个数字

和 returns 数据框或列表。 UI 文件似乎将所有内容正确地组合在一起:

# Required package for shiny apps
library(shiny)

# Possible responses for part of speech
ppos = c("one", "two", "three")



ui <- fluidPage(

# Title using HTML
h1("Cool Title Here", align = "center"),

# Put results in sidebar
sidebarPanel(
        h3("Results"),
        p("Descriptive words"),
        renderTable("finresult")
        ),

# Main panel for instructions and input
mainPanel(
# Sidebar for input
h3("Instructions", align = "center"),
p("Words here. Once you've entered all of the required information, click the \"go\" button to get your results."),

# Numbered list of instructions for input
tags$ol(

# Item 1
tags$li("Instructions for Point 1."),

# Input 1
textAreaInput("x", "Enter your string here:", rows = 3),

# Item 2
tags$li("Instructions for Point 2."),

# Input 2
sliderInput("t", "Indicate your desired number of results:", value = 10,
            min = 1, max = 50),

# Item 3
tags$li("Instructions for Point 3."),

# Input 3
selectInput("y", "Pick from list:", ppos)

# Close numbered list
)
# Close sidebar
),

# Action button to go
actionButton("button", label = "Do it!")

# Close fluidpage
)

但是服务器文件似乎没有产生任何东西。理想情况下,我希望用户每次都点击“执行”按钮来制作脚本 运行 并生成输出。

shinyServer(
        function(input, output, session) {

        observeEvent(input$button,
        coolFunction(input$x, input$y, input$t),
        output$finresult <- renderTable(finresult)
        )
        })

我确定我错过了一些基本的东西。有人看到了吗?

我找到了答案。它在这里:

shinyServer(
        function(input, output, session) {

        observeEvent(input$button,
        output$finresult <- renderTable({
                coolFunction(input$x, input$y, input$t)})
        )
        })