0
ui.R:閃亮使用一個字符串變量列名
library(shiny)
shinyUI( fluidPage(fluidRow(
column(input$PYR,
style = 'padding:25px',
textInput("N_PYR", NULL, width = '192px'),
textInput("RATE_PYR", NULL, width = '192px'),
width = 3),
column(input$CYR,
style = 'padding:25px',
textInput("N_CYR", NULL, width = '192px'),
textInput("RATE_CYR", NULL, width = '192px'),
width = 3)
)))
server.R:
library(shiny)
shinyServer(function(input, output, session) {
# current year ("2015-16" for example)
input$CYR <- reactive({"2015-16"})
input$PYR <- reactive({paste0(
as.numeric(substr(input$CYR, start = 1, stop = 4)-1),
"-",
as.numeric(substr(input$CYR, start = 6, stop = 7)-1))
})
# terminate when window is closed
session$onSessionEnded(function() { stopApp() })
})
如果ui.R改爲
library(shiny)
shinyUI( fluidPage(fluidRow(
column("2014-15",
style = 'padding:25px',
textInput("N_PYR", NULL, width = '192px'),
textInput("RATE_PYR", NULL, width = '192px'),
width = 3),
column("2015-16",
style = 'padding:25px',
textInput("N_CYR", NULL, width = '192px'),
textInput("RATE_CYR", NULL, width = '192px'),
width = 3)
)))
這是所需產品:
目標:聲明一個字符串變量,其值將NOT從用戶端給出(這將在R代碼進行手動更改),以便每當CYR值被改變的UI被更新。這個變量是否在ui.R或server.R中聲明並不重要。