【发布时间】:2018-01-19 01:08:18
【问题描述】:
这是一个源自store input as numeric value to generate three tables in Shiny 的问题,与r shiny error Error in as.vector(x, "character") : cannot coerce type 'closure' to vector of type 'character' 类似但不等于
我想创建一个大表,以便在 Shiny 应用程序中在该表之后创建一些表。
这是我的 MWE (似乎是标题的问题,UI 中的 h3):
完整的服务器。R:
#
# This is the server logic of a Shiny web application. You can run the
# application by clicking 'Run App' above.
#
# Required libraries
if (!require("pacman")) install.packages("pacman")
p_load(shiny,dplyr,DBI,ggplot2)
# Define server logic
shinyServer(
function(input, output) {
display_table <- reactive({
t <- reactive({ as.character(input$year) })
# Read the RCA matrix
long_table = tbl_df(mpg) %>% filter(year == t())
return(long_table)
})
output$year = renderText(input$year)
output$miles <- DT::renderDataTable(DT::datatable({
display_table() %>% select(manufacturer,model,cty,hwy)
}))
output$desc <- DT::renderDataTable(DT::datatable({
display_table() %>% select(manufacturer,model,trans,class)
}))
}
)
完整的 ui.R:
#
# This is the user-interface definition of a Shiny web application. You can
# run the application by clicking 'Run App' above.
#
# Required libraries
if (!require("pacman")) install.packages("pacman")
p_load(shiny)
# Define UI for application that draws a histogram
shinyUI(fluidPage(
verticalLayout(
# Application title
titlePanel("ggplot2's mpg dataset example"),
mainPanel(
# User parameters
column(12,
tags$h3("Parameters"),
selectInput('year', 'Year', c("Select year",1999:2015), selected = 1999)
),
# Display tables
column(12,
#withMathJax(includeMarkdown("Theory.md")),
h3("Miles per gallon for cars made in the year",textOutput("year")),
DT::dataTableOutput("miles"),
h3("Description for cars made in the year",textOutput("year")),
DT::dataTableOutput("desc")
)
)
)
))
【问题讨论】:
-
顺便说一句,如果您发布一个最小的工作示例,这将非常有帮助,请参阅here。包括一些虚假数据,以便其他人可以运行您的代码。它使调试和帮助您解决问题变得更加容易。
-
非常感谢!!我将其更改为带有
mpg数据集的 MWE -
相应地更新了我的答案。
标签: r shiny shiny-server