से बुनाई (लाटेक्स) का उपयोग करके पीडीएफ रिपोर्ट तैयार करना मैं एक चमकदार एप्लिकेशन बनाने की कोशिश कर रहा हूं जो आपको उपयोगकर्ता द्वारा परिभाषित उप-विश्लेषण के अनुसार, अच्छी तरह से स्वरूपित पीडीएफ रिपोर्ट डाउनलोड करने की अनुमति देगा। मुझे this gist मिला जो एक न्यूनतम उदाहरण है, जो ठीक काम करता है। हालांकि, जब मैंने Rstudio गैलरी से 'Miles-per-gallon' example के आधार पर एक साजिश जोड़ने की कोशिश की, तो मैंने कोड को अपनाने का प्रयास करते समय कुछ त्रुटियों में भाग लिया।चमकदार एप्लिकेशन
यहाँ मेरी server.R
कोड है:
library(knitr)
library(datasets)
library(ggplot2)
mpgData <- mtcars
mpgData$am <- factor(mpgData$am, labels = c("Automatic", "Manual"))
shinyServer(function(input, output) {
formulaText <- reactive({
paste("mpg ~", input$variable)
})
# Return the formula text for printing as a caption
output$caption <- renderText({
formulaText()
})
# Generate a plot of the requested variable against mpg and only
# include outliers if requested
output$mpgPlot <- renderPlot({
boxplot(as.formula(formulaText()),
data = mpgData,
outline = input$outliers)
})
myPlot1 <- reactive({
p <- print(ggplot(mpgData, aes(mpg, input$variable)) +
geom_line())
})
myPlot2 <- reactive({
#renderPlot({
p <- print(
boxplot(as.formula(formulaText()),
data = mpgData,
outline = input$outliers)
)
})
output$report = downloadHandler(
filename = 'myreport.pdf',
content = function(file) {
out = knit2pdf('input.Rnw', clean = TRUE)
file.rename(out, file) # move pdf to file for downloading
},
contentType = 'application/pdf'
)
})
और यहाँ मेरी ui.r
कोड
library(shiny)
library(datasets)
shinyUI(fluidPage(
# Application title
titlePanel("Miles Per Gallon"),
# Sidebar with controls to select the variable to plot against mpg
# and to specify whether outliers should be included
sidebarLayout(
sidebarPanel(
textInput('firstname', 'First name', value = 'Adam'),
textInput('lastname', 'Last name', value = 'Smith'),
downloadButton('report'),
selectInput("variable", "Variable:",
c("Cylinders" = "cyl",
"Transmission" = "am",
"Gears" = "gear")),
checkboxInput("outliers", "Show outliers", FALSE)
),
# Show the caption and plot of the requested variable against mpg
mainPanel(
h3(textOutput("caption")),
plotOutput("mpgPlot")
)
)
))
है, जबकि input.Rnw
फ़ाइल इस तरह दिखता है:
\documentclass{article}
\begin{document}
<<names>>=
input$firstname
input$lastname
@
<<>>=
#output$mpgPlot ## N.B. This threw an error! Cannot call an object like this from shiny
print(myPlot1())
@
<<>>=
print(myPlot2())
@
\end{document}
मैं खेल किया गया है इसके साथ कुछ घंटों के लिए, और मैं बहुत अटक गया हूँ। input$names
भाग ठीक काम करता है, लेकिन मैं यह नहीं समझ सकता कि reactive
साजिश में कैसे लाया जाए। त्रुटि/चेतावनी संदेश 'Error: object ’input’ not found'
है, इसलिए मुझे पता है कि यह ui.R
स्क्रिप्ट से पारित इनपुट $ चर परिवर्तनों का पता नहीं लगा रहा है। इस
sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_0.9.3.1.99 knitr_1.6 shiny_0.10.0
loaded via a namespace (and not attached):
[1] bitops_1.0-6 caTools_1.17 colorspace_1.2-4 digest_0.6.4 evaluate_0.5.5 formatR_0.10 grid_3.1.0 gtable_0.1.2
[9] highr_0.3 htmltools_0.2.4 httpuv_1.3.0 labeling_0.2 MASS_7.3-33 munsell_0.4.2 plyr_1.8.1 proto_0.3-10
[17] RColorBrewer_1.0-5 Rcpp_0.11.2 reshape2_1.4 RJSONIO_1.2-0.2 scales_0.2.4 stringr_0.6.2 tools_3.1.0 xtable_1.7-3
यह दिलचस्प है। क्या आप मूल ग्राफिक्स के साथ ggplot2 ग्राफिक्स को प्रतिस्थापित कर सकते हैं और देख सकते हैं कि यह काम करता है या नहीं? जैसे 'प्लॉट (as.formula (formulaText()), डेटा = mpgData)' –
@Yihui धन्यवाद, आपका सुझाव 'प्रिंट (myplot1()) '' plot (as.formula (formulaText()) के साथ' प्रिंट (myplot1()) 'को बदलकर, डेटा = mpgData) '' input.Rnw' में। मैंने ggplot2 को पुनः प्राप्त करने का प्रयास किया है, 'ggPlotText <- प्रतिक्रियाशील ({पेस्ट (' mpg, ', इनपुट $ चर)} ~ '' सर्वर' आर 'और फिर' ggplot (mpgData, aes (ggPlotText()) जोड़कर) + geom_line() 'to' input.Rnw', जो 'formulaText()' के तर्क का पालन करता प्रतीत होता है, लेकिन उत्पादित त्रुटि संदेश कहता है 'त्रुटि: फ़ंक्शन नहीं मिल सका "ggPlotText" '। क्या 'as.formula()' के बराबर है जिसे मैं ggplot2 के 'एईएस (एक्स, वाई)' सम्मेलन के लिए उपयोग कर सकता हूं? 'toString' काम नहीं किया –
यह एक ggplot2 चरणीय स्कोप समस्या की तरह लगता है। हालांकि, ggplot2 लेखकों को इस समस्या की रिपोर्ट करने से पहले, कृपया सुनिश्चित करें कि आपके पास ggplot2 का नवीनतम संस्करण है ('update.packages() 'करें)। –