不确定之前是否曾询问过此事。我是使用RShiny应用程序的新手,我想使用特定CSV文件的特定列中的值来选择selectInput()选择框中的选项。这是我没有CSV的代码,使用了一些虚拟变量。
ui <- shinyUI(fluidPage(
titlePanel(title = h4("PLAYER SELF-CENTERED RATING (PSCR)", align = "center")),
sidebarLayout(
sidebarPanel(
selectInput("selectplayer",
label = h3("Select box"),
choices = list("Choice 1" = 3,
"Choice 2" = 4,
"Choice 3" = 5),
selected = 3)
),
mainPanel(
plotOutput('radarPlot', width = "100%")
)
)
))
坦率地说,我已经相当失去了w.r.t从哪里开始。我还需要使用CSV文件中的数据来创建另一个在shinyServer中的renderPlot()调用中绘制的数据帧,因此需要找到一种方法将CSV数据同时存入服务器和ui。这是一项简单的任务,还是一件困难的事情?任何帮助赞赏!
答案 0 :(得分:3)
您可以在uiOutput
中显示ui
,并在server
中动态生成ui。下面的代码应该给你一个提示。
library(shiny)
server <- function(input, session, output) {
# read csv here
datin <- read.table(text = 'Name,Age,Weight
John,10,40
Hary,20,70
Mike,30,80',
header = TRUE, sep =",", stringsAsFactors = FALSE)
output$select_1 = renderUI({
selectInput("select_input","select", choices = datin['Name'])
})
}
ui <- fluidPage(
uiOutput("select_1")
)
shinyApp(ui = ui, server = server)
答案 1 :(得分:0)
您可以使用侧栏中的uiOutput
生成动态输出,如下面的代码所示:
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "R-shiny app"),
dashboardSidebar(
uiOutput("columnNames") # Dynamic generate UI element
),
dashboardBody(
fluidRow(
column(10,
dataTableOutput('dataview')) #Display data in the tabular form
),
fluidRow(column(3, verbatimTextOutput("column_value"))),
hr()
)
)
server <- function(input, output) {
# Read data from .csv file
data=iris # (for understanding I am using iris dataset)
output$column_value <- renderPrint({
output$columnNames <- renderUI({
selectInput("datacolumn", h4("Select Data Column"), colnames(data)) # Dynamically set selectInput
})
output$dataview <- renderDataTable(data,options = list(pageLength = 10)) # Display the iris dataset
})
}
shinyApp(ui, server)