r语言 - 闪亮的应用程序输出显示在控制台,而不是在主面板



我正在创建一个闪亮的应用程序,用户可以从各种诗歌中选择不同的行来生成一首新的十四行诗。然而,当我运行应用程序时,我的输出不会出现在应用程序中,只会出现在控制台中。我遗漏了什么?

library(shiny) 
library(tidyverse)
Sonnets <- read_csv("https://blades.byu.edu/hon290/hon290cofwsonnets2021.text")
mylines <- c()
library(english)
Vector <- function(mylines) {
for(i in 1:14) {
Sonnets %>%
filter(sonnet==mylines[i]& line==i) %>%
select(text) %>%
print()
}
}
server = function(input, output) (
output$q <- renderText({
paste(vector(c(input$line1, input$line2, input$line3, input$line4, input$line5, input$line6, input$line7, input$line8, input$line9, input$line10, input$line11, input$line12, input$line13, input$14)))
})
)
ui<- fluidPage(
titlePanel("City of Women Sonnets"), 
tabsetPanel(
tabPanel("Sonnet Generator By Line",
sidebarLayout(
sidebarPanel(
h3("Build Your Poem",
fluidRow(
column(6, numericInput("line1", "Line 1", min=1, max=23, value=1)),
column(6, numericInput("line2", "Line 2", min=1, max=23, value=1)),
column(6, numericInput("line3", "Line 3", min=1, max=23, value=1)),
column(6, numericInput("line4", "Line 4", min=1, max=23, value=1)),
column(6, numericInput("line5", "Line 5", min=1, max=23, value=1)),
column(6, numericInput("line6", "Line 6", min=1, max=23, value=1)),
column(6, numericInput("line7", "Line 7", min=1, max=23, value=1)),
column(6, numericInput("line8", "Line 8", min=1, max=23, value=1)),
column(6, numericInput("line9", "Line 9", min=1, max=23, value=1)),
column(6, numericInput("line10", "Line 10", min=1, max=23, value=1)),
column(6, numericInput("line11", "Line 11", min=1, max=23, value=1)),
column(6, numericInput("line12", "Line 12", min=1, max=23, value=1)),
column(6, numericInput("line13", "Line 13", min=1, max=23, value=1)),
column(6, numericInput("line14", "Line 14", min=1, max=23, value=1)),
))
),
mainPanel(h3("poem"),
textOutput("q"))
))
)
)
shinyApp(ui=ui, server=server)

我真的不太懂编程,我只是参加了一个包括基本编码的课程(为了好玩),现在我有点迷失了。

运行上面的代码,我得到了以下错误:

源错误("~/.active-rstudio-document", echo = TRUE):
~/。
输出$q <- renderText({49:粘贴(c(输入$line1,输入$line2);输入$line3,输入$line4,输入$line5,输入$line6,输入$line7输入$line8,输入$line9,输入$line10,输入$line11,输入$line12输入line13美元,14美元

这是由于您的renderText呼叫(input$14而不是input$line14)中的错字造成的。

尝试运行以下命令:

library(shiny)
library(readr)
# library(tidyverse)
# library(english)
# Sonnets <- read_csv("https://blades.byu.edu/hon290/hon290cofwsonnets2021.text")
mylines <- c()
Vector <- function(mylines) {
for(i in 1:14) {
Sonnets %>%
filter(sonnet==mylines[i]& line==i) %>%
select(text) %>%
print()
}
}
ui <- fluidPage(
titlePanel("City of Women Sonnets"), 
tabsetPanel(
tabPanel("Sonnet Generator By Line",
sidebarLayout(
sidebarPanel(
h3("Build Your Poem",
fluidRow(
column(6, numericInput("line1", "Line 1", min=1, max=23, value=1)),
column(6, numericInput("line2", "Line 2", min=1, max=23, value=1)),
column(6, numericInput("line3", "Line 3", min=1, max=23, value=1)),
column(6, numericInput("line4", "Line 4", min=1, max=23, value=1)),
column(6, numericInput("line5", "Line 5", min=1, max=23, value=1)),
column(6, numericInput("line6", "Line 6", min=1, max=23, value=1)),
column(6, numericInput("line7", "Line 7", min=1, max=23, value=1)),
column(6, numericInput("line8", "Line 8", min=1, max=23, value=1)),
column(6, numericInput("line9", "Line 9", min=1, max=23, value=1)),
column(6, numericInput("line10", "Line 10", min=1, max=23, value=1)),
column(6, numericInput("line11", "Line 11", min=1, max=23, value=1)),
column(6, numericInput("line12", "Line 12", min=1, max=23, value=1)),
column(6, numericInput("line13", "Line 13", min=1, max=23, value=1)),
column(6, numericInput("line14", "Line 14", min=1, max=23, value=1))
))
),
mainPanel(h3("poem"),
uiOutput("q"))
))
)
)
server = function(input, output, session) (
output$q <- renderUI({
HTML(paste(input$line1, input$line2, input$line3, input$line4, input$line5, input$line6, input$line7, input$line8, input$line9, input$line10, input$line11, input$line12, input$line13, input$line14, sep = "<br>"))
})
)
shinyApp(ui=ui, server=server)

相关内容

  • 没有找到相关文章

最新更新